Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Long story


With the configuration below Apache gets confused with Python interpreter context. I have three demo sites deployed using this setup and if you refresh them often a race condition occurs and some texts/images coming from the DB gets mixed up between each others.

vhost conf:

<VirtualHost *:80>
    ServerAlias *
    Options FollowSymLinks
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/vhosts/%0
    RewriteEngine On
    RewriteMap lowercase int:tolower

    LogFormat "%{Host}i %h %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/apache2/ vcommon

    # Handle everything except the static/media
    RewriteCond %{REQUEST_URI} !^/(media|static)/(.*)$
    RewriteRule ^/(.*) /var/www/vhosts/%{HTTP_HOST}/apache/django.wsgi/$1
    RewriteRule . - [E=APPLICATION_GROUP:${tolower:%{SERVER_NAME}}]

    # Use the subdomain as unique ApplicationGroup/Process identifier
    # or experience funny results
    RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
    RewriteCond %{HTTP_HOST} ([a-z0-9][-a-z0-9]+)\.demo.motion-m\.ca\.?(:80)?$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%1 -d
    RewriteRule ^(.*) %1/$1 [E=SUBDOMAIN:%1,L]

    # use the "website" part as group name
    WSGIProcessGroup %{ENV:SUBDOMAIN}
    WSGIApplicationGroup %{ENV:SUBDOMAIN}

    <Location ~ /(media|static)/(.*)>
       Order deny,allow
       Options -Indexes
       Allow from all

    <Directory /var/www/vhosts/*/apache>
       Order allow,deny
       Allow from all
       Options ExecCGI
       AddHandler wsgi-script .wsgi


import os, sys, site

os.environ['DJANGO_SETTINGS_MODULE'] = 'projectname.settings'

path = os.path.dirname(os.path.abspath(os.path.join(__file__, '../../')))

if path not in sys.path:
    sys.path.insert(0, '/var/www/vhosts/')
    sys.path.insert(0, '/var/www/vhosts/')
    sys.path.insert(2, '/path/to/django-1.3')
    sys.path.insert(3, '/path/to/django-1.3/django')

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

Any ideas ?


share|improve this question
up vote 1 down vote accepted

The following stands out as possibly wrong to me:

WSGIApplicationGroup %{ENV:SUBDOMAIN}

Why have:

RewriteRule . - [E=APPLICATION_GROUP:${tolower:%{SERVER_NAME}}]

if you are then not using 'APPLICATION_GROUP'.

BTW, have you used:

to validate independent of Django that the exepected daemon process group and sub interpreter is being selected for the respective hosts/URLS.

share|improve this answer
Worked, thanks a lot ! – h3. Jul 20 '11 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.