无法对apache2中的flask应用程序进行故障排除

2024-06-17 11:31:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在一台Linux机器上设置一个flask-restplus应用程序,其中Apache2mod_wsgi。我已经为我的应用程序和wsgi文件创建了virtualHost。当我运行apache时,我能够看到在我的virtualhost中指定的CustomLog文件被创建,但是文件是空的。当我点击服务器时,我得到了404 Not Found错误

我的虚拟主机文件如下所示

    <VirtualHost *>
        ServerName 127.0.0.1
        ErrorLog /win-share/logs/error.log
        CustomLog /win-share/logs/aedmodeling.log common
        WSGIDaemonProcess aedmodeling
        WSGIScriptAlias / /win-share/AED-modeling/web.wsgi
        <Directory /win-share/AED-modeling>
             WSGIProcessGroup aedmodeling
             WSGIApplicationGroup %{GLOBAL}
             Options FollowSymLinks
             AllowOverride None
             Require all granted
        </Directory>
     </VirtualHost>

我的wsgi文件看起来像

    import sys
    import os

    virtual_env_path = os.path.join(os.path.join('aed-modeling- 
    env','bin'),'activate_this.py')
    project_path= os.path.realpath(os.path.dirname(__file__))
    activate_this = 
    os.path.join(os.path.join(project_path,'..'),virtual_env_path)
    exec(compile(open(activate_this).read(), activate_this, 'exec'), 
    dict(__file__=activate_this))

    sys.path.insert(0,project_path)
    from Server import app
    application=app

我的烧瓶应用程序位于Server.py

    from flask import Flask
    app = Flask(__name__)

    @app.route("/")
    def hello():
      return "Hello World!"

    if __name__ == "__main__":
      app.run(host='0.0.0.0')

Tags: 文件pathimportenvapp应用程序sharewsgi