将HTTP重定向到https时,nginx重定向过多

时间:2018-09-09 12:22:39

标签: http redirect nginx https

我正在尝试将http重定向到https。我将letencrypt用于ssl证书。我的配置看起来像这样

server {
        listen 80;
        server_name example.com www.example.com;
        return 301 https://example.com$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 5m;

        server_name example.com www.example.com;

        root /var/www/landing;

        location /.well-known/ {
                root /var/www/;
        }
}

当我尝试访问example.com时,出现浏览器错误,提示重定向太多。 http://example.comhttps://example.com均发生错误,当我转到http://www.example.com时访问服务器块,因为我被重定向到https://example.com,然后得到上面的错误。 / p>

我该如何解决?

1 个答案:

答案 0 :(得分:1)

我做过wget -S https://wellcode.com之后,我认为问题出在dns上,因此在Cloudflare中,我将SSL更改为full并解决了问题