FlaskWSGI未启动/无法访问

2024-03-29 08:50:53 发布

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

我像here所描述的那样配置我的应用程序

但当我试图通过我的域名访问我的应用程序时,我得到的信息是无法访问该网站。但它应该这样做。 有人能帮我吗

我的WSGI文件如下所示:

#!/usr/bin/python
import sys
sys.path.insert(0, '/var/www/flask')

from website import create_app
application = create_app()

我的临时__init__.py文件:

from flask import Flask

def create_app():
    from pathlib import Path
    app = Flask(__name__)
    app.config['APPLICATION_ROOT'] = Path(__file__).parent.absolute()

    app.config['SECRET_KEY'] = 'secret key'

@app.route('/test')
def test_side():
    return 'That\'s a test'

return app

即使我试图通过终端使用命令python启动它并执行:

from website import create_app
app = create_app()
app.run(host='0.0.0.0', debug=True)

我得到以下输出,并立即退出:

* Serving Flask app 'website' (lazy loading)
* Environment: production
  WARNING: This is a development server. Do not use it in a production deployment.
  Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
  WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://192.168.178.36:5000/ (Press CTRL+C to quit)
* Restarting with stat
/usr/bin/python: can't find '__main__' module in '/var/www/flask'

也许这也有帮助-我的apache端配置:

<VirtualHost *:80>
    ServerName my-domain.com

    WSGIDaemonProcess project user=www-data group=www-data threads=5
    WSGIScriptAlias / /var/www/flask/starter.wsgi

    <Directory /var/www/flask>
        WSGIProcessGroup project
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Tags: infromtestimportapp应用程序flaskserver