intermittent problem with two django apps on the same virtual host
I have two Django applications (appsystem and testapp) running in separate folders that are enabled in the same apache virtual host setting (see conf file at the end).
One application displays a page on the root of the domain and that one seems to always work fine but when I go to a URL that should go to the second application then it fails the first time complaining that it can't find the database table despite the fact I can see in the debug page that is loading the right settings.
If I refresh the page then it (testapp) works fine and continues to until I go back to a page from appssytem. If I do that and go back to testapp I must then refresh the page.
Both applications are using开发者_如何学C sqlite for authentication but removing the authentication and sqlite references from the settings file for appsystem didn't seem to make a difference.
The reason I've done it this way is because the idea is that the application that displays the root page (and some admin pages that have unique URLs) will list the other django application installed and display links to click through to.
I also suspect it may be session related because I can go directly to testapp in another browser and it works fine even on the first instance. Because of this I did give each django app its own value for SESSION_COOKIE_NAME but that doesn't seem to have helped.
Does anyone have an idea on what the problem may be?
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /app_www_root
RewriteEngine On
# the root of the box should show the system index - a list of installed apps
RewriteRule ^/$ /appsystem/system_index/ [PT]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /app_www_root/>
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Include /etc/apache2/installed-apps/
## this is what gets pulled in by the include ##
Alias /testapp/static /testapp/static
Alias /testapp/logs /var/log/testapp
WSGIScriptAliasMatch ^/testapp /testapp/django.wsgi
<Directory "/testapp">
Order allow,deny
Allow from all
</Directory>
<Directory "/var/log/testapp">
Order allow,deny
Allow from all
</Directory>
<Location "/testapp/logs">
SetHandler none
Options +Indexes
</Location>
<Location "/testappl/static">
SetHandler none
Options -Indexes
Options +Includes
AddOutputFilter INCLUDES .html
</Location>
## end of included file ##
# wsgi docs advise against trailing slash below
WSGIScriptAlias /appsystem /app_sys/django.wsgi
</VirtualHost>
Have you read http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango at all?
I suspect your problem would be solved if you used mod_wsgi in daemon mode (i.e. via WSGIDaemonProcess).
Try running them in virtualenv with modwsgi.
FWIW, you have various things wrong with your configuration.
Why are you using WSGIScriptAliasMatch directive at all? You should just replace it with WSGIScriptAlias. Don't use WSGIScriptAliasMatch properly and it can stuff up reverse URL resolution.
Using 'SetHandler none' is not required. That is something you may have needed to do for mod_python but not mod_wsgi.
Using Location directive block to apply directives to static file resources as you are is bad practice. You should apply them to the specific directories using Directory directive instead.
As pointed out by others, you are better off using daemon mode. If doing so has worked but you delegate both applications to same single daemon mode process though, then you may have a multi process issue, ie., your application can't handle being run in multiple processes at the same time. If you delegated each to its own daemon process group, then you may have an issue with running them in same process even in case where in separate sub interpreters.
精彩评论