Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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:

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.

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

Your Answer

 
discard

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.