apache/mod_wsgi – how to configure mutiple webapps using different python virtual environments

Question:

Environment: Ubuntu, Apache HTTPD, mod_wsgi compiled with python 3.6, website (assumed): testthisout.com

Problem: I have 2 different webapps which will use 2 different python virtual environments.
They will be hosted at testthisout.com/app1 and testthisout.com/app2

I am struggling to figure how to tell apache to use 2 different virtual environments.

Relevant Apache Configuration:

LoadModule wsgi_module "/apps/python/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/apps/python"



<VirtualHost *:80>
        ServerName testthisout.com
        ServerAdmin [email protected]

        WSGIScriptAlias /app1 /var/www/flaskapp/app1/app1.wsgi
        WSGIScriptAlias /app2 /var/www/flaskapp/app2/app2.wsgi

</VirtualHost>

Ideally app1 should use python packages hosted at /apps/python/python-app1/
Ideally app2 should use python packages hosted at /apps/python/python-app2/

Tried following pages but still don’t understand how to do this…

https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
https://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html

Please let me know any suggestions…

Asked By: Peter

||

Answers:

Finally after a ton of research I came up with something which works…

    ServerName localhost

    WSGIDaemonProcess website1 python-home=/apps/python/python-website1-toolkit display-name=website1
    WSGIScriptAlias /website1 /var/www/flaskapp/python-website1-webapp/website1.wsgi
    <Directory /var/www/flaskapp/python-website1-webapp/>
            WSGIApplicationGroup website1
            WSGIProcessGroup website1
            Order deny,allow
            Allow from all
    </Directory>
    Alias /website1/static /var/www/flaskapp/python-website1-webapp/static
    <Directory /var/www/flaskapp/python-website1-webapp/static/>
            Order allow,deny
            Allow from all
    </Directory>

    WSGIDaemonProcess website2 python-home=/apps/python/python-website2-toolkit display-name=website2
    WSGIScriptAlias /website2 /var/www/flaskapp/python-website2-webapp/website2.wsgi
    <Directory /var/www/flaskapp/python-website2-webapp>
            WSGIApplicationGroup website2
            WSGIProcessGroup website2
            Order deny,allow
            Allow from all
    </Directory>
    Alias /website2/static /var/www/flaskapp/python-website2-webapp/static
    <Directory /var/www/flaskapp/python-website2-webapp/static/>
            Order allow,deny
            Allow from all
    </Directory>


    WSGIDaemonProcess website3 python-home=/apps/python/python-website3-toolkit display-name=website3
    WSGIScriptAlias /website3 /var/www/flaskapp/python-website3-webapp/website3.wsgi
    <Directory /var/www/flaskapp/python-website3-webapp/>
            WSGIApplicationGroup website3
            WSGIProcessGroup website3
            Order deny,allow
            Allow from all
    </Directory>
    Alias /website3/static /var/www/flaskapp/python-website3-webapp/static
    <Directory /var/www/flaskapp/python-website3-webapp/static/>
            Order allow,deny
            Allow from all
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Answered By: Peter
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.