0

Long story

tl;dr:

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>
    ServerName demo.motion-m.ca
    ServerAlias *.demo.motion-m.ca
    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/demo.motion-m.ca 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]
    RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},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
    </Location>

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

django.wsgi

import os, sys, site

site.addsitedir('/usr/lib/python2.5/site-package') 
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/website.demo.motion-m.ca/')
    sys.path.insert(0, '/var/www/vhosts/website.demo.motion-m.ca/projectname/')
    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 ?

Thanks

h3.
  • 189
  • 3
  • 9

1 Answers1

1

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:

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Embedded_Or_Daemon_Mode http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Sub_Interpreter_Being_Used

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

Graham Dumpleton
  • 5,990
  • 2
  • 20
  • 19