I have website build with django and nginx. After adding Let's Encrypt SSL certificat using Certbot I get the error : ERR_TOO_MANY_REDIRECTS
.
Please find the below nginx configuration :
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;
}
}
I think the problem is with return 301; part , but I have searched and I don't know what is wrong.