Reputation: 6697
similar to this: Deploying multiple django apps on Apache with mod_wsgi
I'm trying to host two django apps on mod_wsgi but one is on root. i.e. the WSGI directives would be
WSGIScriptAlias / <path to django wsgi file for app1>
WSGIScriptAlias /app2 <path to django wsgi file for app2>
Just using the WSGIScript aliases like this doesn't seem to work. I tried putting them in location directives but that doesn't work either. Is there a way to accomplish this?
after Graham's answer below I attempted this:
<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app2
WSGIScriptAlias /app2 /<path to app2 wsgi file>/
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app1
WSGIScriptAlias / /<path to app1 wsgi file>
</VirtualHost>
but unfortunately requests to site1.com/app2 still get handled by the django application app1. Did I make a mistake in the config?
Upvotes: 0
Views: 531
Reputation: 58563
Wrong order. Use:
WSGIScriptAlias /app2 <path to django wsgi file for app2>
WSGIScriptAlias / <path to django wsgi file for app1>
The most deeply nested must be first, else '/' will be matched first and override everything else.
UPDATE 1
After additions to question. Now use:
<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
<Location /app2>
WSGIProcessGroup app2
</Location>
WSGIScriptAlias /app2 /<path to app2 wsgi file>/
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIProcessGroup app1
WSGIScriptAlias / /<path to app1 wsgi file>
</VirtualHost>
You need to scope the WSGIProcessGroup
directive to the sub URL so only that sub URL's requests are delegated to the mod_wsgi daemon process group.
Another way of writing above is:
<VirtualHost <server ip>:80>
ServerName site1.com
##### app2 CONFIG
WSGIDaemonProcess app2 python-path=/<path to django app2>/:/<path to virtualenv app2>/ threads=15 display-name=%{GROUP}
WSGIScriptAlias /app2 /<path to app2 wsgi file>/ process-group=app2
##### app1 CONFIG
WSGIDaemonProcess app1 python-path=/<path to django app1>/:/<path to virtualenv app1>/ threads=15 display-name=%{GROUP}
WSGIScriptAlias / /<path to app1 wsgi file> process-group=app1
</VirtualHost>
In other words, use the process-group
option to WSGIScriptAlias
to indicate where each should run.
When using daemon mode and only one application per process, also recommended to add:
WSGIApplicationGroup %{GLOBAL}
This forces use of main Python interpreter context by WSGI application in respective processes, avoiding problems that can arise where some Python packages with C extensions are not implemented correctly so as to work with Python sub interpreters.
Upvotes: 2