Solutions Log

So I only have to figure things out once.

Using Mod_wsgi With Django on Ubuntu

sudo apt-get install libapache2-mod-wsgi

Virtual host configuration:

<VirtualHost *:80>

    ServerAdmin you@example.com
    ServerName example.com
    DocumentRoot /home/you/public_html/example_com/public

    # Django settings
    WSGIScriptAlias / /home/you/public_html/example_com/wsgi_handler.py
    WSGIDaemonProcess example_com user=you group=you processes=1 threads=10
    WSGIProcessGroup example_com

    # Non-Django directories
    Alias /static /home/you/public_html/example_com/public/static/
    <Location "/static">
        SetHandler None
    </Location>

</VirtualHost>

Put a file called wsgi_handler.py in your project folder:

import os, sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
os.environ['DJANGO_SETTINGS_MODULE'] = 'example_com.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Sources

Comments