我已经尝试了不同网站上的所有可能方法。但是没有运气。

目前我正在关注-Run multiple independent Flask apps in Ubuntu

我有两个烧瓶应用

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


两者都有python文件和wsgi文件。

/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


和conf文件

<VirtualHost *:80>
                ServerName http://IP
                ServerAlias IP
                ServerAdmin [email protected]

                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>


当我尝试打开

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


它给我


  找不到在服务器上找不到请求的URL。如果你
  手动输入网址,请检查您的拼写,然后重试。


更新1

仅此app.conf可在IP /烧瓶上使用

<VirtualHost *:80>
                ServerName http://IP
                ServerAlias IP
                ServerAdmin [email protected]
                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>

最佳答案

在我看来,您使用的网址错误。您的WSGIScriptAlias设置为分别在/app1/app2上侦听,因此我将首先尝试访问:

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


并检查WSGIScriptAlias documentation

关于python - 使用Apache运行多个 flask 应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55740294/

10-15 22:10