通过Certbot安装SSL证书后,我的网站出现了错误消息“重定向过多”。经过研究后,我认为我必须从HTTPS-> HTTP重定向到某个地方,因此我尝试对其进行修复,但似乎情况变得更糟了,Apache将不再启动。我是一个初学者,所以我一直在努力了解问题所在。
我正在设置通过SSH访问的CentOS7的VPS,以托管一个简单的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
此后,当我尝试访问以前正常运行的域时,最初收到错误消息“重定向过多”。在尝试将其修复四个小时的问题时,我现在将事情搞砸了,直到Apache似乎无法启动。
现在,当我执行$ sudo systemctl restart httpd
时,出现错误消息“由于控制过程退出并显示错误代码,因此httpd.service的作业失败。有关详细信息,请参见“ systemctl状态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>
对于可能出什么问题的任何指示,我们将不胜感激。
答案 0 :(得分:1)
由于我使用过letencrypt,所以它看起来像这样:
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处于“关闭”状态,从而创建了重定向循环。
答案 1 :(得分:0)
您应该在配置中添加证书,该证书的密钥和中间证书。看起来像:
SSLEngine on
SSLCertificateFile "/path/to/www.example.com.cert"
SSLCertificateKeyFile "/path/to/www.example.com.key"
SSLCACertificateFile "conf/ssl.crt/ca.crt"
有关更多详细信息,请检查apache documentation