Nginx & Django on Webfaction (Part 1a) – Installing

This is aimed at Installing and configuring Django running as a FCGI Process behind Nginx on WebFaction shared hosting but can be altered to work with an almost identical setup on Ubuntu 9.04 (Jaunty).

For those who don’t know Nginx (Engine X) is a Free, open-source, high-performance HTTP server and reverse proxy with the added advantage for shared hosting that it has a low memory footprint – and Django is a high-level Python Web framework with added magic ponies :)

I’m creating this tutorial series so that in 3 months time when I need to set this up again for another project I haven’t forgotten where I put my written notes… (This is based off several threads in the WebFaction Forum, some research into Nginx, and a lot of trial and error getting the upload module to work with Django)

Later on in this series I will be showing how to create fancy ajax upload progress indicators with most of the work done by Nginx, and also how to hand off the work of large downloads back to Nginx.

Right, Let’s get started…

First we need to create a new app in the Webfaction control panel. Create a “new app listening on port” and make a note of the port number
Create A new App
Make a note of the Port Number
Next we need to SSH into our account to configure and install (if you are using windows you can use the Putty SSH client.)
First we need to make some sub directories in our webapp folder and install Django and Flup (needed for the FCGI support later)

cd ~/webapps/<myapp>
mkdir -p bin lib/python2.5
PYTHONPATH=lib/python2.5 easy_install-2.5 -d lib/python2.5 -s bin flup
./bin/ startproject myproject

Now we need to download and untar the latest stable versions of Nginx, Nginx_UploadProgress_Module and PCRE (for the embeded perl in Nginx)
NB. If you need any other modules for Nginx now would be the time to wget them :)

tar -xzf nginx-0.7.61.tar.gz
tar -xzf pcre-7.9.tar.gz
tar -xzf Nginx_uploadprogress_module-0.5.tar.gz

Now lets configure, make and install Nginx

cd pcre-7.9
./configure --prefix=/home/<myusername>/webapps/<myapp>/pcre
cd ../nginx-0.7.61
./configure --prefix=/home/<myusername>/webapps/<myapp> --with-pcre=/home/<myusername>/webapps/<myapp>/pcre-7.9/ --add-module=/home/<myusername>/webapps/<myapp>/nginx_uploadprogress_module/

Assuming we don’t have any errors

make install

Now lets clean up before going any further

cd ..
rm -fr nginx-0.7.61
rm *.gz
rm -fr pcre-7.9

At this point we should have a working install of Nginx and Django, in Part 1b we will show how to configure them both and get our first page served.

Tags: , , ,

12 Responses to “Nginx & Django on Webfaction (Part 1a) – Installing”

  1. bwooceli Says:
    August 14th, 2009 at 17:41

    this is fantastic and well timed. looking forward to 1b :)

  2. tim Says:
    August 15th, 2009 at 14:01

    can’t wait for the next part, thanks!

  3. Brown Says:
    August 19th, 2009 at 07:36

    I liked it. So much useful material. I read with great interest.

  4. seb Says:
    August 20th, 2009 at 10:10

    I hope you’re about to use this only for a small site, I’ve
    a busy site running with an similar setup (nginx + fcg-django) and it is almost impossible to update without dropping connections to at least 3 people. A better way (in my opinion) would be: nginx + apache + mod_wsgi.


  5. tim Says:
    September 5th, 2009 at 20:12

    Was wondering when you are going to publish the next part of this series?

  6. Richard Cooper Says:
    September 5th, 2009 at 20:43

    Sorry I’ve been away for a couple of weeks with no internet access… The good news is that the next couple of posts have been roughed out, and I hope to publish the part 1b in the next 24-48 Hours.

  7. tim Says:
    September 6th, 2009 at 17:00

    Great! Can’t wait.

  8. Nginx & Django on Webfaction - Part 2 | Fighting Rabbits Says:
    September 21st, 2009 at 20:39

    […] after finishing Part 1a and Part 1b you have a working Nginx + Django install on Webfaction. In this installment I’m […]

  9. Marzan Says:
    October 20th, 2009 at 09:03

    Praise you for your help.

  10. Nginx and Django on Webfaction Says:
    November 15th, 2009 at 04:42

    […] Thanks for this tutorial Richard Cooper. […]

  11. Andy Baker Says:
    February 15th, 2010 at 17:19

    Seems to be a lot of people having problems with flup 1.0.3.

    You might want to edit this line:
    PYTHONPATH=lib/python2.5 easy_install-2.5 -d lib/python2.5 -s bin flup

    to be:
    PYTHONPATH=lib/python2.5 easy_install-2.5 -d lib/python2.5 -s bin flup==1.0.2

  12. Nginx Webfaction HOWTO | Nginx Lighttpd Tutorial Says:
    June 3rd, 2011 at 15:16

    […] Nginx & Django on Webfaction (Part 1a) – Installing […]

Leave a Reply