简体   繁体   English

使用apache运行多个flask应用程序

[英]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目前我正在关注 - 在 Ubuntu 中运行多个独立的 Flask 应用程序

I have two flask application我有两个烧瓶应用程序

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

Both having python file and wsgi files.都有 python 文件和 wsgi 文件。

/var/www/html/myapps/flaskapp2/flaskapp2.py /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 /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和conf文件

<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. Not Found 在服务器上找不到请求的 URL。 If you entered the URL manually please check your spelling and try again.如果您手动输入了 URL,请检查您的拼写并重试。

UPDATE 1更新 1

only this app.conf works at IP/flask只有这个 app.conf 适用于 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.在我看来,您使用了错误的 URL。 Your WSGIScriptAlias is set to listen on /app1 and /app2 respectively so I would first try accessing:您的WSGIScriptAlias设置为分别监听/app1/app2所以我首先尝试访问:

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

and check the WSGIScriptAlias documentation并检查WSGIScriptAlias文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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