Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select different wsgi script based on subdomain in Apache?

Is it possible to change the wsgi script used by an apache configuration based on the hostname of the request? I'd like to set up a system where various wsgi applications can be deployed and then run by simply using a subdomain to automatically map to the correct wsgi script. I'm mostly trying to avoid having to change the conf file every time another application is deployed.

<VirtualHost *:80>
    ServerName mysite.us
    ServerAlias *.mysite.us

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

    <Directory /home/ubuntu/mysite>
        WSGIProcessGroup mysite
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>
like image 446
apiguy Avatar asked Mar 14 '26 23:03

apiguy


1 Answers

Have you tried setting an 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 have to finesse it a little for your purposes, and you need apache2 to capture regex values with SetEnvIf.

http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#setenvif

Then you should be able to use that:

WSGIScriptAlias / /home/ubuntu/mysite/%{subdomain}.wsgi.py
like image 189
Kasapo Avatar answered Mar 16 '26 13:03

Kasapo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!