I\'m trying to run two or more Flask applications in separate virtual directories with Apache, like http://localhost/site1
for /var/www/myapps/app1 and
I spent more time on this and, if I'm starting to understand Apache terminology and configuration a little better, I cannot use virtual hosts for this purpose. VirtualHost
sections are intended for serving different host names (multiple domains or subdomains.)
For configuring parallel applications as subdirs I could have used Directory
sections instead. I also didn't realize some of the WSGI*
directives in the config file could appear more than once. This new knowledge allowed me to produce the following single config file that does what I wanted. So instead of enabling one Apache site for each app, I could enable a single site with the directories configured in it.
# this goes in /etc/apache2/sites-available/
ServerName localhost
# logs configuration
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIDaemonProcess site1 user=myserviceuser group=myserviceuser threads=5 python-home=/var/www/myapps/app1:/var/www/myapps/app1/env/lib/python2.7/site-packages
WSGIScriptAlias /site1 /var/www/myapps/app1/application.wsgi
WSGIApplicationGroup site1
WSGIProcessGroup site1
Order deny,allow
Allow from all
WSGIDaemonProcess site2 user=myserviceuser group=myserviceuser threads=5 python-home=/var/www/myapps/app2:/var/www/myapps/app2/env/lib/python2.7/site-packages
WSGIScriptAlias /site2 /var/www/myapps/app2/application.wsgi
WSGIApplicationGroup site2
WSGIProcessGroup site2
Order deny,allow
Allow from all
EDIT:
I later followed Graham Dumpleton's suggestion and removed the activate_this
stuff from application.wsgi and changed the WSGIDaemonProcess
directive lines to:
WSGIDaemonProcess site1 user=myserviceuser group=myserviceuser threads=5 python-home=/var/www/myapps/app1/env