Multiple mod_wsgi apps on one virtual host directing to wrong app Multiple mod_wsgi apps on one virtual host directing to wrong app python python

Multiple mod_wsgi apps on one virtual host directing to wrong app


I've had multiple WSGI apps running on a single Apache install, and found that the easiest thing to do is just have multiple process groups-- one for each of the apps.

One downside, versus actually trying to get a single process to run both (or more) apps, is that this might use a little more resident memory than you could get away with otherwise. But it keeps them pretty well separated and avoids hassle. And that might not be a concern for you (it wasn't for me).

(It might not be that bad either, they might be able to share a lot of text pages? That's just idle speculation; I haven't verified this in any way, as my setup was not at all memory-starved)

Here's some snippets of my httpd.conf, approximately:

WSGIDaemonProcess khdx_wsgi user=galdosd group=galdosd maximum-requests=10000WSGIScriptAlias /khdx /home/galdosd/khdxweb/rel/khdx/apache/django.wsgi<Location /khdx>WSGIProcessGroup khdx_wsgi</Location>WSGIDaemonProcess sauron_wsgi user=galdosd group=galdosd maximum-requests=10000WSGIScriptAlias /sauron /home/galdosd/finalsauronweb/django-root/apache/django.wsgi<Location /sauron>WSGIProcessGroup sauron_wsgi</Location>


Domingo Ignacio's answer set me on the right track. I'd like to point out an important fact about making it work: The two process groups must be within the same VirtualHost. (This is based on my tests with Ubuntu 12.04.3 LTS, Apache 2.2.22 and a couple of WSGI apps written in Python.)

For example, this did not work for me, resulting in the ability to access app1 but a 404 error for app2:

<VirtualHost *>        WSGIDaemonProcess app1 user=someuser group=somegroup threads=5        WSGIScriptAlias /app1 /app1/app1.wsgi        <Location /app1>                WSGIProcessGroup app1        </Location></VirtualHost><VirtualHost *>        WSGIDaemonProcess app2 user=someuser group=somegroup threads=5        WSGIScriptAlias /app2 /app2/app2.wsgi        <Location /app2>                WSGIProcessGroup app2        </Location></VirtualHost>

Removing the middle and tags, so as to have a single VirtualHost, solved the problem:

<VirtualHost *>        WSGIDaemonProcess app1 user=someuser group=somegroup threads=5        WSGIScriptAlias /app1 /app1/app1.wsgi        <Location /app1>                WSGIProcessGroup app1        </Location>        WSGIDaemonProcess app2 user=someuser group=somegroup threads=5        WSGIScriptAlias /app2 /app2/app2.wsgi        <Location /app2>                WSGIProcessGroup app2        </Location></VirtualHost>


I've had trouble with this myself. Instead of trying to get the Apache configuration right, I decided instead to use a single WSGIScriptAlias and have WSGI middleware which routed requests to the correct applications. My code is at https://github.com/zhemao/flotilla. I haven't tested it that much, so use it with caution, but I hope it helps.