简体   繁体   中英

django SECURE_SSL_REDIRECT with nginx reverse proxy

Is it secure to set SECURE_SSL_REDIRECT=False if I have nginx setup as a reverse proxy serving the site over https?

I can access the site over SSL if this is set this to False , where as if it is True , I receive too many redirects response.

NOTE: nginx and django run from within docker containers.

My nginx.conf looks like:

upstream config {
    server web:8000;
}

server {
    listen 80;
    server_name _;
    return 301 https://$host$request_uri;
}

server {

    listen                  443 ssl;
    server_name             _;
    ssl_certificate         /etc/ssl/certs/cert.com.chained.crt;
    ssl_certificate_key     /etc/ssl/certs/cert.com.key;

    location / {
        proxy_pass http://config;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location /staticfiles/ {
        alias /home/app/web/staticfiles/;
    }

}

EDIT: Added http to https redirect in nginx.conf.

You need to add the following to your "location /" block:

location / {
     ...
     proxy_set_header X-Forwarded-Proto $scheme;
     ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM