Nginx + Django + FastCGI + SSL
My favourite method for deploying Django sites in production is with Nginx at the frontend talking FastCGI to a dedicated Django process (either flup or supervisord) via a UNIX or TCP socket.
There are two recurring issues that I keep running into costing hours of fruitless Googling. Hopefully, this will help others:
SCRIPT_NAMEis evil! At least it’s useless in Django, and if present as a FastCGI parameter, Django will trip that away from your request URI and you’re almost certainly going to get/no matter what URI you navigate to! So, saveSCRIPT_NAMEfor your PHP stuff, and leave it out of the parts where you expect to be talking to Django.
If you haveinclude fastcgi_paramsin yournginx.conf, make sure it’s not hiding behind thefastcgi_paramsfile.- If you want SSL to work, i.e. for Django to know that it is serving in
httpsmode, and to build properLocationheader for redirects, you need to include the following in the appropriate section of yournginx.conf:
fastcgi_param HTTPS on;
Obviously, if you’re running both plain and SSL version, you shouldn’t be sharing that section or Django will just thinking that it is in SSL mode even when it’s not.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
July 10th, 2010 at 3:57 pm
[...] This post was mentioned on Twitter by Django Ireland, Wil Tan. Wil Tan said: Nginx + Django + FastCGI + SSL http://shar.es/mFj9w [...]
April 7th, 2011 at 7:12 am
Thanks for that HTTPS on tip!