很长的故事
TL;博士:
在Apache下面的configuration与Python解释器上下文混淆。 我有三个使用此设置部署的演示站点,如果经常刷新它们,则会出现竞争情况,并且来自数据库的某些文本/图像会相互混淆。
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()
有任何想法吗 ?
谢谢
以下对我可能是错误的:
WSGIApplicationGroup %{ENV:SUBDOMAIN}
为什么有:
RewriteRule . - [E=APPLICATION_GROUP:${tolower:%{SERVER_NAME}}]
如果你不使用'APPLICATION_GROUP'。
顺便说一句,你用过:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Embedded_Or_Daemon_Mode http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Sub_Interpreter_Being_Used
独立于Djangovalidation是否为各个主机/ URLselect了被执行的守护进程组和子解释器。