Serving Django Admin over HTTPS behind a Nginx Proxy

I was deploying my first Django application today on a production server. Nginx is the proxy server and gunicorn is the WSGI web server. Supervisor is being used to ensure the gunicorn workers are always re-spawned if they die. The firewall is setup to only allow HTTPS connections. After a lot of tweaking the settings, I was finally able to see my page over the public internet.

An interesting thing was happening when I was trying to get to the admin. I would use access the admin over HTTPS and login. However I was being redirected to HTTP after the login and I would never see a page as the firewall would block the request. But when I reload the admin page using HTTPS I can see that I was logged in. So basically I needed to figure out what to do so Django admin would be served over HTTPS after login.

After some snooping around on the net, I find the answer on stackoverflow. So without further adieu:

Leave a Reply

Your email address will not be published. Required fields are marked *