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:

# 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}/ \
 --vacuum \
 --python-path ${HOME}/webapps/${APPNAME} \
 --wsgi wsgi
# Start nginx

The –wsgi flag tells uwsgi where to find the Django 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
uwsgi --uid 1002 -w customer2app --limit-as 128 -p 3 -M -s
uwsgi --uid 1003 -w django3app --limit-as 96 -p 6 -M -s

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.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s