hi,
I tried to deploy my django channels application on linux with nginx + daphne
I am getting ERR_TOO_MANY_REDIRECTS
issue again and again i even tried --proxy-headers in daphne but still getting the error.
settings.py
# CSRF settings
CSRF_TRUSTED_ORIGINS = ["https://"+host for host in allowed_hosts_list]
CSRF_COOKIE_AGE = 60 * 60 * 5 # Default: 31449600 seconds (5 hour)
CSRF_COOKIE_DOMAIN = None # Set the cookie domain
CSRF_COOKIE_HTTPONLY = False # Default: False
CSRF_COOKIE_PATH = '/' # Default: '/'
CSRF_COOKIE_SAMESITE = 'Lax' # Default: 'Lax'
CSRF_COOKIE_SECURE = True # Default: False
# HTTPS settings
SECURE_HSTS_SECONDS = 30 # Unit is seconds; *USE A SMALL VALUE FOR TESTING!* change to higher value for production
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
i have use this command
daphne -b 0.0.0.0 -p 8000 --proxy-headers myproject.asgi:application
Nginx config:
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
upstream backendserver {
server backend:8000;
}
server {
listen 443 ssl;
http2 on;
server_name mydomain.com;
keepalive_timeout 70;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
location /static/ {
alias /opt/djangofiles/staticfiles/;
}
location /media/ {
alias /opt/djangofiles/media/;
}
location / {
proxy_pass http://backendserver;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
if (!-f $request_filename){
proxy_pass http://backendserver;
break;
}
}
location /ws/ {
proxy_pass http://backendserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}