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
  5. Run script using: bash -e | tee
  6. Modify file
  7. Add hack to
  8. Copy or update fabfile to use new file
  9. Setup DB
  10. Edit
  11. Add symbolic link to
  12. Add 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:

# 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.