Choose another wsgi script based on subdomain in Apache?

Is it possible to change the wsgi script used by apache config based on the hostname of the request? I would like to set up a system where various wsgi applications can be deployed and then started, simply using a subdomain to automatically map to the correct wsgi script. Basically I try to avoid having to change the conf file every time another application is deployed.

<VirtualHost *:80>
    ServerAlias *

    WSGIDaemonProcess mysite
    #can I use a different value here based on the domain?
    WSGIScriptAlias / /home/ubuntu/mysite/

    <Directory /home/ubuntu/mysite>
        WSGIProcessGroup mysite
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all



source to share

1 answer

Have you tried setting the environment variable captured from the request uri and assigning the WSGIScriptAlias ​​path to that var?

Something like:

SetEnvIf HTTP_HOST "^(\w+).domain.tld" subdomain=$1


You may need to refine it a bit for your own purposes and you need apache2 to capture the regex values ​​with SetEnvIf.

Then you should be able to use this:

WSGIScriptAlias / /home/ubuntu/mysite/%{subdomain}




All Articles