"Job for httpd.service failed because the control process exited with error code." 我该如何解决这个问题?

"Job for httpd.service failed because the control process exited with error code." How do I fix this?

通过 Certbot 安装 SSL 证书后,我的网站出现错误消息 "too many redirects"。经过一些研究,我认为我必须在某个地方从 HTTPS -> HTTP 进行重定向,所以我试图修复它,但似乎我把它弄得更糟了,Apache 将不再启动。我是一个完全的初学者,所以我很难理解哪里出了问题。

我正在设置一个 VPS 与 CentOS7 通过 SSH 访问来托管一个简单的 html 网站。我设置了基础知识(相关的可能是 UFW 防火墙、Cloudflare 作为 DNS、Apache 2.4.6)并设法在我的域上显示测试页面。

然后我继续使用本教程设置我的虚拟主机:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7 按照本教程设置 letsencrypt:https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-centos-7

在此之后,我最初在尝试访问我的域时收到错误消息 "too many redirects",该域以前工作正常。虽然连续四个小时试图修复此问题,但我现在把事情搞砸了,以至于 Apache 似乎无法启动。

现在,当我执行 $ sudo systemctl restart httpd 时,我收到错误消息 "Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" 和 "journalctl -xe" 了解详细信息。"

[USER@host ~]$ sudo systemctl status httpd.service
* httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2019-01-23 00:57:39 UTC; 20s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 26023 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 24468 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
  Process: 26021 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 26021 (code=exited, status=1/FAILURE)

Jan 23 00:57:39 host systemd[1]: Starting The Apache HTTP Server...
Jan 23 00:57:39 host systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jan 23 00:57:39 host kill[26023]: kill: cannot find process ""
Jan 23 00:57:39 host systemd[1]: httpd.service: control process exited, code=exited status=1
Jan 23 00:57:39 host systemd[1]: Failed to start The Apache HTTP Server.
Jan 23 00:57:39 host systemd[1]: Unit httpd.service entered failed state.
Jan 23 00:57:39 host systemd[1]: httpd.service failed.

我对 /etc/httpd/conf/httpd.conf 所做的唯一更改是将底部的 IncludeOptional conf.d/*.conf 更改为 IncludeOptional sites-enabled/*.conf

我的虚拟主机设置目前如下:

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot /var/www/example.com/public_html
    Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost _default_:443>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog /var/www/example.com/error.log
    CustomLog /var/www/example.com/requests.log combined
    SSLEngine on
</VirtualHost>

如有任何错误提示,我们将不胜感激。

您应该在配置中添加证书、此证书的密钥和中间证书。这看起来像:

SSLEngine on
SSLCertificateFile "/path/to/www.example.com.cert"
SSLCertificateKeyFile "/path/to/www.example.com.key"
SSLCACertificateFile "conf/ssl.crt/ca.crt"

有关详细信息,请查看 apache documentation

因为我使用了 letsencrypt,它看起来像这样:

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

这解决了 apache 的错误。 SSL 加密还没有工作,如果我发现这是这些行的问题,我会回来更新它。

编辑:此设置现在对我来说工作正常。 SSL 加密不起作用的问题是由于 Cloudflare 中的 "off" 上有 SSL,这创建了一个重定向循环。