【问题标题】:"Job for httpd.service failed because the control process exited with error code." How do I fix this?“httpd.service 的作业失败,因为控制进程以错误代码退出。”我该如何解决?
【发布时间】:2023-03-20 15:22:02
【问题描述】:

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

我正在设置一个通过 SSH 访问 CentOS7 的 VPS,以托管一个简单的 html 网站。我设置了基础知识(相关的可能是 UFW 防火墙、作为 DNS 的 Cloudflare、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

在此之后,我最初在尝试访问以前正常工作的域时收到错误消息“重定向太多”。在尝试连续四个小时解决此问题时,我现在把事情搞砸了,以至于 Apache 似乎无法启动。

现在,当我执行$ sudo systemctl restart httpd 时,我收到错误消息“httpd.service 的作业失败,因为控制进程以错误代码退出。有关详细信息,请参阅“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.

我对@9​​87654325@ 所做的唯一更改是将底部的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>

如果有任何可能出现问题的指示,将不胜感激。

【问题讨论】:

  • 在 apache 配置(SSL 部分)中,您没有定义证书、密钥和中间证书)
  • 添加为答案。如果这对您有用,请随意添加和/或接受答案

标签: apache ssl centos certbot


【解决方案1】:

由于我使用了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 中“关闭”了 SSL,从而创建了重定向循环。

【讨论】:

    【解决方案2】:

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

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

    更多详情请查看apache documentation

    【讨论】:

    • (删除评论并添加为替代答案)
    猜你喜欢
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    • 1970-01-01
    • 2019-12-31
    相关资源
    最近更新 更多