自从我使用 certbot 放置 SSL 证书以来,我的网站上出现了臭名昭著的"重定向过多"错误。
我一直在这里寻找几个小时来找到我的问题的解决方案,尝试了不同的解决方案,但没有一个在我的情况下奏效。
关于服务器的一些背景信息:Debian 9 和 Apache2(都是最新的(
我正在努力使用我的 VirtualHost 文件来摆脱这个"重定向太多"错误。其中有两个,一个用于非HTTPS连接,一个用于HTTPS连接,当然两者都在Apache中激活。
这里是非HTTPS配置文件(非常简单(
<VirtualHost *:80>
ServerAdmin contact@website.com
ServerName website.com
Redirect permanent / https://www.website.com/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin contact@website.com
ServerName www.website.com
Redirect permanent / https://www.website.com/
</VirtualHost>
这是HTTPS配置文件
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin contact@website.com
ServerName website.com
Redirect permanent / https://www.website.com/
SSLCertificateFile /etc/letsencrypt/live/website.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:443>
ServerAdmin contact@website.com
ServerName www.website.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/letsencrypt/live/website.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
正如您所注意到的,我希望"官方"地址是"https://www.website.com",并且所有没有"www."和/或"https"的连接都被重定向到该地址。
有人可以帮助我吗?非常感谢 !
我使用CloudFlare,它突然停止处理此错误。 我将CloudFlare SSL设置从灵活更改为完整,这解决了我遇到的问题。
在查看了几个小时的 Apache2 conf 后,我查看了我的 DNS 记录......那里一团糟,一些 301 重定向创建了循环......
因此,如果有人遇到同样的问题,请考虑在花费数小时在 Apache 配置文件;)之前检查您的域配置
我的问题解决了!
我遇到了同样的问题。不得不添加到我的/etc/apache2/sites-available/example.com-le-ssl.conf
RequestHeader set X-Forwarded-Proto https
希望这对某人有所帮助。
我看到的一件事是DNS级别的CDN和DDoS保护设置。
我还发现,在 Cloudflare 将 SSL 级别从灵活更改为完整解决了从 http 重定向到 https 时重定向过多的问题。