Proxy headers can be surprisingly tricky with Django. Did you also account for forwarded host and HTTPS settings?
Django 403 behind a proxy fix
John Bannister
●1 ●2 ●8
calendar_today
• schedule2 min read
— Originally published at portal.uppcoder.com
2 Comments
Lennox
•
John Bannister
•
@[Lennox] Good point. Forwarded host only matters if your proxy changes the Host header. Nginx with proxy_set_header Host $host, Traefik and Caddy pass the original, so Django sees the real name and you just need it in ALLOWED_HOSTS. If yours doesn't, USE_X_FORWARDED_HOST = True, with the same caveat as the proto header but only if the proxy always sets it.
For HTTPS: once SECURE_PROXY_SSL_HEADER is set you can turn on SECURE_SSL_REDIRECT, SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE. Without the proxy header, SECURE_SSL_REDIRECT gives you an endless redirect loop, which is the other classic gotcha.
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- You Tube
- Tiktok
- Premium Subscription
- Terms of Service
- Early Builders
chevron_left
More From John Bannister
Related Jobs
- Spanish Educational Video Scriptwriter / Instructional Content DeveloperIdlewild Co · Full time · Charleston, WV
- 212403 Mobile User Interface DeveloperProCom · Full time · Santa Clara, CA
Commenters (This Week)
manojkagitha
4 comments
Iurie Mocanu
1 comment
JAgostoni
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!