After a hearing a great Gunicorn talk by Brian Riley of EdgeCast.com at the LADjango meetup I decided it was time to dive in to a modern server for Django. After getting around a few bumps I realized setting up Gunicorn with NGINX was easy. Even though I appreciate - and was blown away by - Graham Dumpleton's mod_wsgi for Apache, I feel it's time to push forward. I am glad I did and as a result, if I am unable to use Heroku on a project I will now most likely use NGINX, Gunicorn, and Postgres as the stack for some Django projects.

Gunicorn is a simple pip install. This set up assumes you are using virtualenv, that your environments are located in ~/envs, and your projects are located in ~/webapps. For the purpose of this article I will call the Django project "guni".

At this point we can manually start Gunicorn with, "$ gunicorn_django --bind=127.0.0.1:8001" and see the "Welcome to your first Django page..." at yourdomain.com, if yourdomain.com pointing to your server/DNS. However, we need to set up monitoring to auto start Gunicorn during system reboots and such. I am using Ubuntu (10.10). It ships with a program for this called Upstart. Ironically, Upstart was giving me a headache, so I decided to use another program called Supervisor instead, which was easy:

Install supervisor

$ sudo apt-get install supervisor

Create and save a new supervisor configuration file for your project in the location below:

$ sudo vim /etc/supervisor/conf.d/guni.conf

Copy the block between the dotted lines and configure for your project