Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple mod_wsgi apps on one virtual host directing to wrong app

I'm trying to get two (or more) Django applications set up at subdirectories under the same domain, e.g.:

http://example.com/site1/ http://example.com/site2/ 

I know that normally this works fine by setting up an apache virtualhost like this:

<VirtualHost *:80>     ...     WSGIScriptAlias /site1 /path/to/site1.wsgi     WSGIScriptAlias /site2 /path/to/site2.wsgi </VirtualHost> 

Now, I've verified that each site works individually. But when I try to run both side-by-side, apache sends me to whichever site the worker process loaded first. Example:

  1. Restart apache configured to serve 6 threads
  2. Load example.com/site1/, get the correct page
  3. Load example.com/site2/, get the correct page
  4. Repeat 2 and 3 2 more times.
  5. Refresh example.com/site1/ repeatedly, watch it cycle from site to site.

Effectively, for any given number of worker processes, it cycles through the total number of them sending the request to whichever one it hit first regardless of the WSGIScriptAlias directive. No matter what I do (setting WSGIProcessGroup, daemon mode vs. embedded mode, or directives) it continues to exhibit this behavior.

If anyone can point out what I'm doing wrong here, that would be phenomenal!

like image 509
Gabriel Hurley Avatar asked Jul 06 '11 01:07

Gabriel Hurley


1 Answers

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=10000 WSGIScriptAlias /khdx /home/galdosd/khdxweb/rel/khdx/apache/django.wsgi <Location /khdx> WSGIProcessGroup khdx_wsgi </Location>  WSGIDaemonProcess sauron_wsgi user=galdosd group=galdosd maximum-requests=10000 WSGIScriptAlias /sauron /home/galdosd/finalsauronweb/django-root/apache/django.wsgi <Location /sauron> WSGIProcessGroup sauron_wsgi </Location> 
like image 190
Domingo Ignacio Avatar answered Sep 22 '22 16:09

Domingo Ignacio