Nginx

NGINX SSL“ERR_TOO_MANY_REDIRECTS”

  • October 23, 2018

我有使用 django 和 nginx 建構的網站。使用Certbot添加Let’s Encrypt SSL 證書後,出現錯誤:。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;**部分,但我已經搜尋過,我不知道出了什麼問題。

由於您使用的是 CloudFlare,因此您還需要在 CloudFlare 設置中啟用 SSL。由於您的源伺服器上有一個真正的 SSL 證書,因此您應該在 CloudFlare 設置中使用 Full SSL(嚴格)。

引用自:https://serverfault.com/questions/936857