Clone wiki

OOMMPPAA / Ubuntu server

Setting up a Ubuntu OOMMPPAA gunicorn, nginx and Django stack.

This assumes you have set up OOMMPPAA as outlined in this tutorial

Massive thank you to Michał Karzyński for this wonderful blogpost. The following is largely based on that.

Firstly make this file in ~/CHOC/src/WebApp/gunicornstart.bash

NAME="Cocoa"                                  # Name of the application
DJANGODIR=~/CHOC/src/WebApp        # Django project directory
SOCKFILE=~/CHOC/src/WebApp/run/gunicorn.sock  # we will communicte using this unix socket
USER=abradley                                       # the user to run as
GROUP=abradley                                    # the group to run as
NUM_WORKERS=5                                    # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=WebApp.wsgisettings             # which settings file should Django use
DJANGO_WSGI_MODULE=WebApp.wsgi                     # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the environment
export RDBASE=~/RDKit/rdkit

# Create the run directory if it doesn't exist
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --timeout $TIMEOUT

You can start the server now by

bash ~/CHOC/src/WebApp/gunicornstart.bash

You will need to change the databse setting in to wherever you're .db file is.

Create a file in /home/abradley/CHOC/src/WebApp/ and enter the full path of the database file as below:

import os, sys
name = /home/abradley/CHOC/src/WebApp/data/OOMMPPAA_db'
user = ''
password = ''
host = ''            # Empty for localhost through domain sockets or '' for localhost through TCP.
port = ''
extra_apps = ['IOhandle',

You could configure a Postgres or MySQL database by altering these settings if you would prefer a different engine

Now lets start up the nginx server

mkdir ~/CHOC/logs/

Make the nginx config file:

sudo vim /etc/nginx/sites-available/Cocoa

The full paths are required so replace /home/anthony with whatever your home directory is

upstream Cocoa_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  server unix:/home/abradley/CHOC/src/WebApp/run/gunicorn.sock fail_timeout=0;

server {

    listen   80;
    server_name localhost;

    client_max_body_size 4G;

    access_log /home/abradley/CHOC/logs/nginx-access.log;
    error_log /home/abradley/CHOC/logs/nginx-error.log;

    location /static/ {
        alias   /home/abradley/CHOC/src/WebApp/data/static/;

    location /media/ {
        alias  /home/abradley/CHOC/src/WebApp/data/data/media/;

    location / {
        # an HTTP header important enough to have its own Wikipedia entry:
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # enable this if and only if you use HTTPS, this helps Rack
        # set the proper protocol for doing redirects:
        # proxy_set_header X-Forwarded-Proto https;

        # pass the Host: header from the client right along so redirects
        # can be set properly within the Rack application
        proxy_set_header Host $http_host;

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        # set "proxy_buffering off" *only* for Rainbows! when doing
        # Comet/long-poll stuff.  It's also safe to set if you're
        # using only serving fast clients with Unicorn + nginx.
        # Otherwise you _want_ nginx to buffer responses to slow
        # clients, really.
        # proxy_buffering off;

        if (!-f $request_filename) {
            proxy_pass http://Cocoa_server;

Simlink this to sites-enabled and remove the default simlink

sudo ln -s /etc/nginx/sites-available/Cocoa /etc/nginx/sites-enabled/Cocoa
sudo rm /etc/nginx/sites-enabled/default

Restart the server

sudo service nginx restart
bash ~/CHOC/src/WebApp/gunicornstart.bash