简体   繁体   中英

running multiple flask application using apache

I have tried with all possible approaches on different websites. But have no luck.

Currently I am following - Run multiple independent Flask apps in Ubuntu

I have two flask application

/var/www/html/myapps/flaskapp2
/var/www/html/myapps/flaskapp

Both having python file and wsgi files.

/var/www/html/myapps/flaskapp2/flaskapp2.py

from flask import Flask
app = Flask(__name__)
@app.route("/newflask")
def hello():
    return "Hello,welcome to flask website!"
if __name__ == "__main__":
    app.run()

/var/www/html/myapps/flaskapp2/flaskapp2.wsgi

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/myapps/flaskapp2/")

from flaskapp2 import app as application

and conf file

<VirtualHost *:80>
                ServerName http://IP
                ServerAlias IP
                ServerAdmin admin@mywebsite.com

                WSGIDaemonProcess app1 user=karim group=karim threads=5 python-home=/var/www/html/myapps/flaskapp:/home/k/projects_r/venv_3.7/lib/python3.7/site-packages
                WSGIScriptAlias /app1 /var/www/html/myapps/flaskapp/flaskapp.wsgi
                <Directory /var/www/html/myapps/flaskapp>
                        WSGIApplicationGroup app1
                        WSGIProcessGroup app1
                        Order allow,deny
                        Allow from all
                </Directory>


                WSGIDaemonProcess app2 user=karim group=karim threads=5 python-home=/var/www/html/myapps/flaskapp2:/home/k/projects_r/venv_3.7/lib/python3.7/site-packages
                WSGIScriptAlias /app2 /var/www/html/myapps/flaskapp2/flaskapp2.wsgi
                <Directory /var/www/html/myapps/flaskapp2>
                        WSGIApplicationGroup app2
                        WSGIProcessGroup app2
                        Order allow,deny
                        Allow from all
                </Directory>

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

When I try to open

http://IP/myapps/flaskapp/flask
http://IP/myapps/flaskapp2/newflask

It gives me

Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

UPDATE 1

only this app.conf works at IP/flask

<VirtualHost *:80>
                ServerName http://IP
                ServerAlias IP
                ServerAdmin admin@mywebsite.com
                WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi
                <Directory /var/www/html/flaskapp>
                        Order allow,deny
                        Allow from all
                </Directory>

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

It looks to me that you are using the wrong URLs. Your WSGIScriptAlias is set to listen on /app1 and /app2 respectively so I would first try accessing:

http://IP/app1
http://IP/app2

and check the WSGIScriptAlias documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM