Skip to content

How to use nginx, uWSGI and supervisord

mattupstate edited this page Apr 18, 2012 · 5 revisions

Change By Us was originally developed to run using lighttpd and fastcgi. As an alternative it can also be run using nginx, uWSGI, and supervisord. The combination of nginx and uWSGI is arguably faster and and more stable. The following are basic instructions on how to setup your server.

Installation

First install the required software:

nginx

Ubuntu

Ubuntu doesn't always have the latest nginx builds and its required to have a more recent build that includes the uWSGI module, so add the repository info (including the repository key):

$ sudo echo "deb http://nginx.org/packages/ubuntu/ lucid nginx" | sudo tee --append /etc/apt/sources.list
$ sudo echo "deb-src http://nginx.org/packages/ubuntu/ lucid nginx" sudo tee --append /etc/apt/sources.list
$ sudo wget http://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
$ sudo apt-get update -qq

And install:

$ sudo apt-get install nginx

OS X

Ideally you're using homebrew:

$ brew install nginx

uWSGI

Ubuntu

You'll most likely want to install into your system Python path:

$ pip install uwsgi

OS X

$ brew install uwsgi

supervisord

You'll most likely want to install into your system Python path:

$ pip install supervisor

Configuration

nginx

Use the template located at etc/nginx/nginx.conf.tmpl as a guide if you're trying to run this setup locally. Ensure that the configuration is loaded into the main nginx configuration using a line such as the following in /etc/nginx/nginx.conf:

http {
    ...
    include /path/to/app/etc/nginx.conf;
    ...
}

You may want to follow the sites-enabled/available pattern on web accessible Ubuntu instances. In that case add the following line to your nginx config:

http {
    ...
    include /path/to/sites-enabled/*;
    ...
}

And link your configuration:

$ sudo ln -s /path/to/app/etc/nginx.conf /path/to/sites-enabled/cbu

supervisord

Use the template located at etc/supervisor/supervisor.conf.tmpl as a guide if you're trying to run this setup locally. Ensure that the configuration is loaded into the main supervisor configuration using a line such as the following in /etc/supervisord.conf:

[include]
files = /path/to/app/etc/supervisor.conf

On your web accessible Ubuntu instances you may want to, again, follow a simliar pattern to nginx. First, however, supervisord does not come with a default init.d script. One can be installed using the following commands:

$ wget https://raw.github.com/gist/1791689/4cfc202200ccf2a0b09ccdb14d99faf75a760a8c/supervisord.sh
$ sudo cp supervisord.sh /etc/init.d/supervisor
$ sudo chmod +x /etc/init.d/supervisor
$ sudo /usr/sbin/update-rc.d -f supervisor defaults

Then to setup the apps-availble/enabled pattern, add the following line to /etc/supervisord.conf:

[include]
files = /etc/supervisor/apps-enabled/*

And link the configuration:

$ sudo ln -s /path/to/app/etc/supervisor.conf /etc/supervisor/apps-enabled/cbu

Running

Now you just need to make sure nginx and supervisord are running...

Clone this wiki locally