NGINX SSL“ERR_TOO_MANY_REDIRECTS”

NGINX SSL“ERR_TOO_MANY_REDIRECTS”

我使用 django 和 nginx 构建了网站。添加后让我们加密SSL 证书使用Certbot我收到错误:ERR_TOO_MANY_REDIRECTS

请查看以下 nginx 配置:

server {
    listen 80 default_server;
    server_name www.example.com example.com;

    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    server_name www.example.com example.com;

    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


    location /favicon.ico { 
        access_log off; 
        log_not_found off; 
    }
    location /static/ {
        root /home/project;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

我认为问题在于返回301;部分,但我已经搜索过了,不知道哪里出了问题。

答案1

由于您使用的是 CloudFlare,因此您还需要在 CloudFlare 设置中启用 SSL。由于您的源服务器上有真正的 SSL 证书,因此您应该在 CloudFlare 设置中使用完整 SSL(严格)。

相关内容