views:

186

answers:

0

I have a Django based CMS that uses Django's sites framework and Nginx/Apache/mod_wsgi virtual hosts to run a number of websites on different domains. We're assessing other options for a Django stack and have the CMS running with a single site on a new server with Nginx proxying to Gunicorn (gunicorn_django, specifically).

Although this works great for a single site, I'm not sure how to configure Gunicorn for multiple sites. The problem is that with Apache/mod_wsgi, we could set the DJANGO_SETTINGS_MODULE for mod_wsgi to the appropriate site's settings.py

import os, sys

def inflight(filename):
    """
    Calculate absolute path to the folder containing "myfile.wsgi", then
    append to the PYTHONPATH.
    """
    ROOT = ('/').join(os.path.abspath(os.path.dirname(filename)).split('/')[0:-1])
    sys.path.append(ROOT)
    sys.path.append(os.path.join(ROOT, 'website'))

    sys.stdout = sys.stderr
    # Each website should have a settings file: /www/mysite.com/website/settings.py
    os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
    import django.core.handlers.wsgi
    return django.core.handlers.wsgi.WSGIHandler()

At the moment I'm thinking that I have to have a different instance of Gunicorn for each virtual host site we run but that seems overkill for the traffic we get to most of our sites.

Does anyone run Gunicorn with Django's sites framework and can give a hint to how it's configured?