SSL 重定向过多 - Apache

Zem*_*mou 3 apache ssl redirect

自从我使用 certbot 安装 SSL 证书以来,我的网站上出现了臭名昭著的“重定向过多”错误。

我一直在这里寻找几个小时来解决我的问题,尝试了不同的解决方案,但没有一个对我的情况有效。

关于服务器的一些背景信息:Debian 9 with 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>
Run Code Online (Sandbox Code Playgroud)

这是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>
Run Code Online (Sandbox Code Playgroud)

正如您所注意到的,我希望“官方”地址是“ https://www.website.com ”,并且所有连接都没有“www”。和/或“https”被重定向到这个地址。

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

Zem*_*mou 5

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

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

我的问题解决了!

  • 对于 CloudFlare 用户,检查 SSL 是否设置得太“满” (4认同)

nap*_*aps 5

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