Nginx, Uwsgi, Virtualenv and Django on Ubuntu 12.04

September 11, 2012 - IT

First install required applications.

sudo apt-get install nginx uwsgi uwsgi-plugin-python python-virtualenv

Versions of packages that will be used:

  • Nginx
  • Uwsgi 1.0.3+dfsg-1ubuntu0.1
  • Virtualenv
  • Django 1.4.1


I store my project in ~/projects. Now I'm creating python virtual environment for my project and I'm installing Django.

cd ~/projects/
source bin/activate
pip install django startproject project

Nginx configuration.

IMHO, by default, nginx is configured for basic tasks. I won't change this configuration in this entry. Configuration files are stored in /etc/nginx/sites-available. Go to this directory and create a new file.

cd /etc/nginx/sites-available

It's example configuration.

server {
    listen  80;
    access_log /var/log/nginx/eshlox.net_access.log;
    error_log /var/log/nginx/eshlox.net_error.log;

    location / {
        uwsgi_pass  unix:///tmp/;
        include     uwsgi_params;

    location /media/  {
        alias /home/eshlox/projects/;

    location  /static/ {
        alias  /home/eshlox/projects/;

We must create symlink to enable this.

cd /etc/nginx/sites-enabled
ln -s ../sites-available/ .


Like with Nginx.. configuration files are stored in /etc/uwsgi/apps-available. Go to this directory and create a new file.

cd /etc/uwsgi/apps-available


vhost = true
plugins = python
socket = /tmp/
master = true
enable-threads = true
processes = 2
wsgi-file = /home/eshlox/projects/
virtualenv = /home/eshlox/projects/
chdir = /home/eshlox/projects/
touch-reload = /home/eshlox/projects/

Enable this.

cd /etc/uwsgi/apps-enabled/
ln -s ../apps-available/ .

That's all. Now, run this services.

sudo service nginx start
sudo service uwsgi start

Of course, this is a very basic configuration. Change it according to your needs.