使用SSL重定向太多 - Apache

时间:2018-01-27 15:42:03

标签: apache ssl redirect

我对臭名昭着的"太多的重定向"因为我在certbot上安装了SSL证书,所以我的网站上出现了错误。

我一直在这里找几个小时找到问题的解决方案,尝试了不同的解决方案,但没有一个能解决我的问题。

关于服务器的一些背景信息:使用Apache2的Debian 9(两者都是最新的)

我正在努力摆脱我的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>

正如您所注意到的,我希望&#34;官方&#34;地址为&#34; https://www.website.com&#34;和所有连接没有&#34; www。&#34;和/或&#34; https&#34;被重定向到这个地址。

有人能帮助我吗? 非常感谢!

5 个答案:

答案 0 :(得分:2)

在查看Apache2 conf后几个小时,我查看了我的DNS记录...... 那里很乱,有一些301重定向创建循环......

因此,如果有人遇到同样的问题,请考虑在花费数小时在Apache配置文件上检查您的域配置;)

我的问题解决了!

答案 1 :(得分:0)

我见过的一件事是因为这是DNS级别的CDN和DDoS保护设置。

答案 2 :(得分:0)

我使用CloudFlare,它突然停止处理此错误。我将CloudFlare SSL设置从“灵活”更改为“完整”,从而解决了我遇到的问题。

答案 3 :(得分:0)

我还发现,将Cloudflare的SSL级别从“灵活”更改为“完全”可以解决从http重定向到https时重定向过多的问题。

答案 4 :(得分:0)

我有同样的问题。必须添加到我的/etc/apache2/sites-available/example.com-le-ssl.conf

RequestHeader set X-Forwarded-Proto https

希望这对某人有帮助。

相关问题