Easy nginx + django (fastcgi) setup
A quick and dirty on getting nginx and django running through fastcgi. This assumes that you’ve gotten nginx, django and flup installed and running (I’ll only cover the configuration of the virtual host that hosts the django site).
The best way to get things up and running (while still being able to test the setup) is to run the django fastcgi process in non-daemonized mode.
python manage.py runfcgi socket=/home/www/mysite.example.com/run/mysite.sock pidfile=/home/www/mysite/run/mysite.pid method=threaded daemonize=false
Now configure an nginx virtual-host in /usr/local/nginx/conf/nginx.conf (or your config) like so:
# This serves the development site mysite.example.com.
server {
listen 80;
server_name mysite.example.com;
access_log /home/www/mysite.example.com/log/access.log;
error_log /home/www/mysite.example.com/log/error.log;
location / {
# Specifying the location of all the fastcgi parameters that are required to-
# allow nginx to talk to the django fastcgi process.
fastcgi_pass unix:/home/www/mysite.example.com/run/moviedb.sock;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_NAME $server_name;
# Pass authorisation requests through to the application.
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
And that’s it – bring nginx up (which ever way you do on your OS) and away you go!