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

问题描述 投票:0回答:4

安装 Web 服务器后 Apache 无法启动。 (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.
apache centos
4个回答
1
投票

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

在 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

否则服务将无法启动


1
投票

3 月 28 日 12:18:22 box-40395.localdomain httpd[30144]: SSLCertificateFile: 文件 '/etc/pki/tls/certs/localhost.crt' 不存在或为空

错误消息表示 SSLCertificateFile 丢失。您可以使用以下命令生成这些文件来解决此问题。

sudo openssl req -newkey rsa:2048 -nodes -keyout /etc/pki/tls/private/localhost.key -x509 -days 365 -out /etc/pki/tls/certs/localhost.crt

0
投票

安装

systemctl reload httpd
后运行
mod_ssl
时出现此错误(我之前仅提供 HTTP 服务)。

解决方案:运行

systemctl restart httpd.service
;将创建文件
/etc/pki/tls/certs/localhost.crt
/etc/pki/tls/private/localhost.key
,并且 httpd 将正常启动。


-7
投票

错误信息很清楚:

SSLCertificateFile:文件

/etc/pki/tls/certs/localhost.crt
不存在或为空

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

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

完成后,只需

sudo systemctl start httpd
即可启动 Apache。

© www.soinside.com 2019 - 2024. All rights reserved.