Multiple Django Sites Served by Nginx on Webfaction

In an attempt to reduce my memory usage, I wanted to try to server multiple Django sites from one Nginx app using uwsgi. Here are my notes.

Here is the install for a single Django site on Nginx. We will work from that.

Here is the shell script for starting nginx and uwsgi:

#!/bin/bash
APPNAME=nginx_1
# Start uwsgi
${HOME}/webapps/${APPNAME}/bin/uwsgi \
 --uwsgi-socket "${HOME}/webapps/${APPNAME}/uwsgi.sock" \
 --master \
 --workers 1 \
 --max-requests 10000 \
 --harakiri 60 \
 --daemonize ${HOME}/webapps/${APPNAME}/uwsgi.log \
 --pidfile ${HOME}/webapps/${APPNAME}/uwsgi.pid \
 --vacuum \
 --python-path ${HOME}/webapps/${APPNAME} \
 --wsgi wsgi
# Start nginx
${HOME}/webapps/${APPNAME}/bin/nginx

The –wsgi flag tells uwsgi where to find the Django wsgi.py file. If we are going to serve multiple Django sites, we will need to do something with this. Note this flag can also be -w.

This page looks promising. Check out the Virtual Hosting section. At the bottom, they show how to start uwsgi for three sites:

uwsgi --uid 1001 -w customer1app --limit-as 128 -p 3 -M -s 127.0.0.1:3031
uwsgi --uid 1002 -w customer2app --limit-as 128 -p 3 -M -s 127.0.0.1:3032
uwsgi --uid 1003 -w django3app --limit-as 96 -p 6 -M -s 127.0.0.1:3033

Note the -w flag.

Now that I understand this better, I am not sure my approach will help much with memory consumption. In my current nginx, uwsgi app the nginx process uses about 2MB while the uwsgi process uses about 80MB. Thus the number of nginx processes is irrelevant compared to the number of uwsgi processes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s