ssl Nginx不断重定向域到https(ERR_TOO_MANY_REDIRECTS)

but5z9lq  于 2023-08-06  发布在  Nginx
关注(0)|答案(1)|浏览(193)

当我试图去https://example.com/网站,它不断重定向我到https://example.com/,但当我试图去https://example.com/example-page/,一切都打开ok。指定的页面https://example.com/无法从ERR_TOO_MANY_REDIRECTS端工作(301永久移动)
我的配置:

server {
    server_name example.com;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://192.168.183.21:84;
        proxy_redirect off;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name example.com;
    return 404; # managed by Certbot

}

字符串
我也试过这个配置:

server {
    listen 80;
        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
        error_page 497 301 =307 https://$host:$server_port$request_uri;
        location /{
            proxy_pass http://192.168.183.20:86/;
            proxy_redirect off;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Ssl on;
        }
}

8ehkhllq

8ehkhllq1#

您是否尝试过从其他浏览器访问您的网站,而您尚未访问该网站?或清除与该站点关联的所有浏览器缓存数据?永久重定向(301)由浏览器本身缓存,因此下次浏览器请求站点时,它会自动请求重定向的站点。可能你在https://example.com上有一个错误的配置,它应该被重定向到https://example.com,浏览器存储了它,现在在缓存中有那个循环。你的配置在我看来很好。

相关问题