First install required applications.
sudo apt-get install nginx uwsgi uwsgi-plugin-python python-virtualenv
Versions of packages that will be used:
- Nginx 1.1.19.1
- Uwsgi 1.0.3+dfsg-1ubuntu0.1
- Virtualenv 1.7.1.2-1
- Django 1.4.1
Virtualenv.
I store my project in ~/projects. Now I’m creating python virtual environment for my project and I’m installing Django.
cd ~/projects/virtualenv eshlox.netcd eshlox.netsource bin/activatepip install djangodjango-admin.py 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-availablevim eshlox.net
It’s example configuration.
server { listen 80; server_name eshlox.net www.eshlox.net; access_log /var/log/nginx/eshlox.net_access.log; error_log /var/log/nginx/eshlox.net_error.log;
location / { uwsgi_pass unix:///tmp/eshlox.net.sock; include uwsgi_params; }
location /media/ { alias /home/eshlox/projects/eshlox.net/project/project/media/; }
location /static/ { alias /home/eshlox/projects/eshlox.net/project/project/static/; }}
We must create symlink to enable this.
cd /etc/nginx/sites-enabledln -s ../sites-available/eshlox.net .
Uwsgi.
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-availablevim eshlox.net.ini
Edit eshlox.net.ini
[uwsgi]vhost = trueplugins = pythonsocket = /tmp/eshlox.net.sockmaster = trueenable-threads = trueprocesses = 2wsgi-file = /home/eshlox/projects/eshlox.net/project/project/wsgi.pyvirtualenv = /home/eshlox/projects/eshlox.netchdir = /home/eshlox/projects/eshlox.net/projecttouch-reload = /home/eshlox/projects/eshlox.net/project/reload
Enable this.
cd /etc/uwsgi/apps-enabled/ln -s ../apps-available/eshlox.net.ini .
That’s all. Now, run this services.
sudo service nginx startsudo service uwsgi start
Of course, this is a very basic configuration. Change it according to your needs.