生成自签名证书后 Apache 无法启动

Apache Won't Start After Generating Self Signed Cert

Apache 无法启动,出现错误...

1:08:52 a.m.  [Apache]  Error: Apache shutdown unexpectedly.
1:08:52 a.m.  [Apache]  This may be due to a blocked port, missing dependencies, 
1:08:52 a.m.  [Apache]  improper privileges, a crash, or a shutdown by another method.
1:08:52 a.m.  [Apache]  Press the Logs button to view error logs and check
1:08:52 a.m.  [Apache]  the Windows Event Viewer for more clues
1:08:52 a.m.  [Apache]  If you need more help, copy and post this
1:08:52 a.m.  [Apache]  entire log window on the forums

在我生成自签名证书之前,Apache 在 these instructions 之前工作。我还使用端口 443 重定向更新了虚拟主机文件。

Apache 日志没有告诉我任何有用的信息,因为在尝试启动 Apache 时不会生成错误。我检查了 netstat,但 443 上没有任何内容。

编辑:我通过注释掉

再次启动了服务器
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf

所以我的 SSL 配置中的某些东西导致它无法启动。据我所知,我已经在 SSL 配置中正确设置了证书和密钥文件。

编辑 2:运行 httpd -t 我收到错误 SSLCertificateFile: file 'C:/my/xampp/location/apache/conf/ssl.crt/server.crt' does not exist or is empty

果然我创建的crt文件是空的!密钥文件不是。我会尝试重新创建它。

编辑 3:好的,我重新创建了 .crt 和密钥文件,它们都有内容。 conf 语法通过,但 Apache 不会启动。我现在可以看到一个错误:Certificate and private key www.example.com:443:0 from /conf/ssl.crt/server.crt and /conf/ssl.key/server.key do not match AH00016: Configuration Failed

设置证书时,是否必须使用通用名称,使其与服务器名称完全匹配?即如果虚拟主机中的服务器名称是 www.example.com:443,我是否必须将端口包含在完全限定域 URL 通用名称中?

编辑 4:看到我的配置现在看起来不错,我尝试了 different tutorial and the cert seems OK but I get the error described hereopenssl x509 -in my.crt -text 表示证书末尾有一个奇数大小的块。我不明白新生成的证书会如何损坏。我错过了什么吗?

背景是我在尝试设置 Let's Encrypt 为我的 Win XAMPP 服务器生成便携式 SSL 证书时遇到错误(我在 Ubuntu 机器上执行此操作,因为那里更容易使用客户端)。但是我得到了“Correct zName not found for TLS SNI challenge”。其中一个建议是先有一个自签名证书。这让我尝试了上面的方法。

愚蠢的错误。我在与 crt 文件相同的目录中有密钥文件

在默认配置中我没有意识到每个文件都有自己的目录

配置中的目录 conf/ssl.crt/ 看起来很像 conf/ssl.key/

将密钥放在它自己的目录中(在删除已经存在的密钥之后)修复了它。

奇怪的是,我看过的教程中的文件都在同一个目录中。我认为这不重要,只要你 link 他们正确。