gpt4 book ai didi

python - 使用 apache 运行多个 Flask 应用程序

转载 作者:行者123 更新时间:2023-12-01 01:01:43 32 4
gpt4 key购买 nike

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

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

我有两个 flask 应用程序

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

它给了我

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

更新1

只有这个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>

最佳答案

我认为您使用了错误的网址。您的 WSGIScriptAlias 设置为分别监听 /app1/app2,因此我首先尝试访问:

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

并检查 WSGIScriptAlias documentation

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

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com