【问题标题】:how to Running Flask with Apache2 and Mod-WSGI如何使用 Apache2 和 Mod-WSGI 运行 Flask
【发布时间】:2021-06-01 08:32:56
【问题描述】:

我正在尝试在我的覆盆子中使用 Apache2 和 Mod-WSGI 运行 Flask 我得到了在此服务器上找不到的请求 URL 我尝试编辑 000-default.conf 但应用程序不会使用 Mod-WSGI。 我用过python 3

谁能告诉我是什么问题?

谢谢 这是我来自 apache2 的状态:

这是 app.wsgi:

#!/usr/bin/python3
import sys
sys.path.insert(0, '/var/www/html/prox')
from init import app as application

这是 000-default.conf

Listen 5000

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/prox

    LogLevel debug

    WSGIScriptAlias / /var/www/html/prox/app.wsgi
    WSGIDaemonProcess prox processes=5 threads=1 user=pi group=pi display-name=%{GROUP}
    WSGIProcessGroup prox
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIChunkedRequest On
    ErrorLog ${APACHE_LOG_DIR}/error-5000.log
    CustomLog ${APACHE_LOG_DIR}/access-5000.log combined

    <Directory /var/www/html/prox>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
    </Directory>

这个应用程序:命名为 app.py

from flask import Flask, render_template

app = Flask(__name__)
@app.route('/')
def home_page():
    return render_template('index.html')

app.debug = True
if __name__ == '__main__'
    app.run()

这是 journalctl -xe :

我收到了这个错误

【问题讨论】:

    标签: python-3.x apache flask raspberry-pi3 mod-wsgi


    【解决方案1】:

    例如,尝试在您的 apache 服务器上启动烧瓶应用程序本身。

    // Find your flask app
    export FLASK_APP=<YOUR_FILE>
    
    // Host it on your local network
    flask run --host=0.0.0.0
    

    这将启动服务器,确保您处于虚拟环境和存储烧瓶应用程序的目录中。

    【讨论】:

    • 您好,谢谢,我试了一下,但出现错误:文件“/usr/lib/python3.7/socketserver.py”,第 466 行,在 server_bind self.socket.bind(self.server_address) OSError: [Errno 98] 地址已在使用中
    • 可能这个端口还在被apache的服务器占用。在您的 apache 安装的站点可用文件中运行 sudo a2dissitite 000-default.confsudo a2dissite &lt;your app conf&gt;. From there reload apache with sudo service apache2 restart. While there make sure your wsgi is up to date by running sudo apt install libapache2-mod-wsgi-py3 -y' 希望它有所帮助
    猜你喜欢
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-30
    • 2016-07-24
    • 2018-07-08
    • 2021-06-23
    相关资源
    最近更新 更多