使用Apache运行多个烧瓶应用程序

时间:2019-04-18 06:31:41

标签: python flask wsgi

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

我目前正在关注-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

和配置文件

<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>

当我尝试打开

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

它给了我

  

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

更新1

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

<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>

1 个答案:

答案 0 :(得分:1)

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

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

并检查WSGIScriptAlias documentation