Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Django projects running simultaneously and mod_wsgi acting werid

I'm trying to run two Django projects simultaneously. I happened to be using mod_wsgi, and found the site is acting weird. Perhaps there would be a workaround, but I'd like to know what I'm missing and how to solve the problem.

In the apache configuration

# Setup the Python environment
# As root owns basically everything on a Amazon AMI and root
# cannot be used. Create a folder under /var/run/wsgi
# with the owner as ec2-user and group ec2-user.
WSGISocketPrefix /var/run/wsgi
# Call your daemon process a name
WSGIDaemonProcess pydaemon processes=1 threads=5
# Call your daemon process group a name
WSGIProcessGroup pydaemon
# Point to where the handler file is. This will be different
# If you are using some other framework.
WSGIScriptAlias /test /var/www/html/test/wsgi.py
WSGIScriptAlias /proto /var/www/html/proto/wsgi.py

After Apache restarts, if I connect to '/proto', then the proto site is shown. However, then I connect to '/test', without restarting Apache, the proto site is still shown, and I cannot access to the test site.

Now I restart Apache, this time I go to '/test' first. The test site comes up! However, if I go to '/proto' it still shows the test site, not the proto site.

What could make this happen? I added SESSION_COOKIE_PATH differently for each application just in case, but the problem still exists.


[UPDATED]

I also tried as the following, to give different WSGI application group names, but without luck.

Alias /cuedit /var/local/test/wsgi.py
<Location /test>
SetHandler wsgi-script
Options +ExecCGI
WSGIApplicationGroup test
</Location>
Alias /proto /var/local/proto/wsgi.py
<Location /proto>
SetHandler wsgi-script
Options +ExecCGI
WSGIApplicationGroup proto
</Location>

[UPDATED]

I changed from the daemon mode to the embedded mode. I guess the problem was two instances shared the same mod_wsgi daemon process so their namespace collide.

I would expect they should be handled correctly, but in the daemon mode I couldn't get it right.

like image 228
MHC Avatar asked Mar 06 '12 09:03

MHC


1 Answers

Use this as a workaround:

WSGIDaemonProcess pydaemon-1 processes=1 threads=5
WSGIDaemonProcess pydaemon-2 processes=1 threads=5

WSGIScriptAlias /test /var/www/html/test/wsgi.py

<Location /test>
WSGIProcessGroup pydaemon-1
WSGIApplicationGroup %{GLOBAL}
</Location>

WSGIScriptAlias /proto /var/www/html/proto/wsgi.py

<Location /proto>
WSGIProcessGroup pydaemon-2
WSGIApplicationGroup %{GLOBAL}
</Location>

This will force each application into separate daemon process group and no way they should be able to interfere with each other.

If that still doesn't work, you have problems with your WSGI script file somehow.

like image 86
Graham Dumpleton Avatar answered Oct 14 '22 15:10

Graham Dumpleton