Donate to support Ukraine's independence.

18 Mar'11

Django nginx Debian

How to make a simple install of django onto small Debian-6 VPS.
I’ll stick with flup, which enables python to serve fastcgi and some
other protocols.
I use it in conjunction with nginx, which in turn is used save memory.


1 upgrade the system

apt-get upgrade

2 install required dependencies

apt-get install nginx-light postgresql python-django python-psycopg2 python-flup python-imaging

3 configure nginx

you may want to use emacs, vim, or nano. in case of last - you should read how to configure nano better.

server {
    server_name report.loc; location / {
        root   /var/www/siteyour/www;
        include /usr/local/nginx/fastcgi.conf;
    location /media {
        alias /var/www/siteyour/www/uploads;
    location /admin-media {
        alias  /usr/share/pyshared/django/contrib/admin/media;
//here you should notice the difference between nginx alias and root
// while testing, you may remove default entry and add a directive `listen 80` right
// after the opening server brace

and fastcgi.conf

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_pass_header Authorization;
fastcgi_intercept_errors off;

4 postgres

su postgres
createdb yoursite
createuser youruser
nano /etc/postgresql/9.0/main/pg_hba.conf

modify one of the last lines to use `trust` instead of `ident`-based authentication

/etc/init.d/postgresql restart

6 troubles

you may issue a 403 error on your static files. that’s not getting fixed with chmod 0777 ./*. You just have to

groupadd site
useradd -g site site
chown site /path/to/yoursitedir

and change the first line of nginx.conf to

user site site;

7 run python runfcgi method=threaded host= port=3434

8 restart nginx

/etc/init.d/nginx restart

*9 copy your files

scp -r yorsitedir login@addr:path

this will create yourdir inside the path on the addr host

That’s it! Comment if you experience any troubles!

** few more links on nginx: