-
Notifications
You must be signed in to change notification settings - Fork 27
How to use nginx, uWSGI and supervisord
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.
First install the required software:
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
Ideally you're using homebrew:
$ brew install nginx
You'll most likely want to install into your system Python path:
$ pip install uwsgi
$ brew install uwsgi
You'll most likely want to install into your system Python path:
$ pip install supervisor
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
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/2422960/aa5f0aaf759f6bdb587e009d2c8be3e5a3cba895/supervisor.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
Now you just need to make sure nginx and supervisord are running...