Setting up a New Nginx Instance on Webfaction

These are mostly notes for me.

  1. Create custom app listening on port
  2. Create app for serving static
  3. If its an https site and you want http redirected to it, do this.
  4. Edit bash script make_nginx.sh
  5. Run script using: bash -e make_nginx.sh | tee make_nginx.sh
  6. Modify server.py file
  7. Add server.py hack to settings.py
  8. Copy or update fabfile to use new server.py file
  9. Setup DB
  10. Edit wsgi.py
  11. Add symbolic link to wsgi.py
  12. Add local_settings.py to app
  13. Make sure email is on in local_settings
  14. Make sure ALLOWED_HOSTS is correct in project settings

Useful resources:

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.