Tonight I spent sometime getting Pinax - Django swiss army knife - to work on nginx via fastcgi on my Ubuntu 9.10 box. Here is a step by step guide. First of course we need to install nginx, pretty easy with Ubuntu:
from http://durdn.com/blog/2009/10/07/how-to-setup-pinax-with-nginx/
sudo apt-get install nginx
Create a new file called appname
in /etc/nginx/sites-available/
like the following:upstream djangoserv {
server 127.0.0.1:8801;
}
server {
listen 80;
server_name alkemic;
access_log /var/log/nginx/appname.access.log;
location ^~ /site_media/ {
alias /home/nick/dev/projects/pinax07/appname/site_media/;
autoindex on;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc \
|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
#access_log off;
expires 30d;
}
location / {
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:8801;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
}
Link it to sites-enabled so that we know it’s going to be started up (meanwhile you want to remove the default one):sudo ln -s /etc/nginx/sites-available/appname /etc/nginx/sites-enabled/
Startup nginx with:sudo /etc/init.d/nginx start
Activate your pinax installation (change the path to where you have installed your Pinax virtual environment):source /home/nick/dev/projects/pinax07/bin/activate
Install flup (required to have manage.py run as fastcgi) in your virtual env:pip install flup
Symlink all the static assets into the site_media folder:css -> /home/nick/dev/projects/pinax07/appname/media/css/
img -> /home/nick/dev/projects/pinax07/appname/media/img
js -> /home/nick/dev/projects/pinax07/appname/media/js
pinax -> ../../lib/python2.6/site-packages/pinax/media/default/pinax/
snd -> /home/nick/dev/projects/pinax07/appname/media/snd
swf -> /home/nick/dev/projects/pinax07/appname/media/swf
Launch the python fastcgi process: python ./manage.py runfcgi method=threaded host=127.0.0.1 port=8801
Or:python ./manage.py runfcgi method=prefork host=127.0.0.1 port=8801
Note that you might need to move your development environment to use a
proper db like MySQL because otherwise the app will have problems
finding your sqlite db file. You should have now your app running on the
blazing fast nginx.from http://durdn.com/blog/2009/10/07/how-to-setup-pinax-with-nginx/