由于缺少 SSLCertificateFile,Apache 无法在 CentOS 7 中启动

Apache won't start in CentOS 7 due to missing SSLCertificateFile

Apache 在安装 Web 服务器后没有启动。 (CentOS 7)

● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2020-03-28 12:18:22 MSK; 16ms ago
Docs: man:httpd.service(8)
Process: 30144 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 30144 (code=exited, status=1/FAILURE)
Status: "Reading configuration..."

Mar 28 12:18:22 box-40395.localdomain systemd[1]: Starting The Apache HTTP Server...
Mar 28 12:18:22 box-40395.localdomain httpd[30144]: AH00526: Syntax error on line 103 of /etc/httpd/conf.d/ssl.conf:
Mar 28 12:18:22 box-40395.localdomain httpd[30144]: SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty
Mar 28 12:18:22 box-40395.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Mar 28 12:18:22 box-40395.localdomain systemd[1]: Failed to start The Apache HTTP Server.
Mar 28 12:18:22 box-40395.localdomain systemd[1]: Unit httpd.service entered failed state.
Mar 28 12:18:22 box-40395.localdomain systemd[1]: httpd.service failed.

报错信息很清楚:

SSLCertificateFile: file /etc/pki/tls/certs/localhost.crt does not exist or is empty

删除此无效配置或添加 missing/fix 现有证书文件。无论哪种方式都必须在 Apache 启动之前修复配置。

获取 SSL 证书超出了 Whosebug 的范围。网上有很多资源,你也可以试试ServerFault

完成后,只需 sudo systemctl start httpd 启动 Apache。

您可以尝试创建一个假证书。

在 centos 中有一个方便的脚本可能会有所帮助

$ cd /etc/pki/tls/certs
$ sudo ./make-dummy-cert localhost.crt

此脚本生成自签名证书和证书的私钥。

因此 /etc/httpd/conf.d/ssl.conf 中的 SSLCertificateKeyFile 可以被注释掉

SLCertificateFile /etc/pki/tls/certs/localhost.crt
# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

否则服务无法启动