Multiple Flask apps on the same virtualhost - Apache2




Assumptions:
-you already know Flask,apache2.
-Running ubuntu.
-everything needed is installed.

otherwise go the flask official website, after you deployed your first flask app with apache2 then try the below



let say you have two applications app1 and app2

app1 resides in /apps/app1
and app2 in /apps/app2

in apps/app1/myapp1.wsgi
import sys
sys.path.insert(0, "/apps/app1")
from myapp1 import app as application

in apps/app2/myapp2.wsgi
import sys
sys.path.insert(0, "/apps/app2")
from myapp2 import app as application

we also assume that app1.py is the main file in your flask app1 (the same to app2)

now the trick is in
/etc/apache2/sites-available/yoursite.conf
<VirtualHost *>
SferverName your.website.whatever

WSGIDaemonProcess app1 user=youruser group=yourgroup threads=5
WSGIScriptAlias /app2 /apps/app1/myapp1.wsgi
WSGIScriptAlias /app1 /apps/app2/myapp2.wsgi

<Directory /apps/app1/myapp1>
WSGIProcessGroup myapp1
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

reference:
-http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html
-flask official website


Comments

Popular Posts