简体   繁体   English

在 WSGI 上部署 Flask 时找不到 404

[英]404 Not Found when deploying Flask on WSGI

I've been using Flask for a while for development but recently decided to address the "This server should not be used for production" warning.我一直在使用 Flask 进行开发,但最近决定解决“此服务器不应用于生产”警告。 I've spent several hours trying to get wsgi to work to no avail.我花了几个小时试图让 wsgi 工作无济于事。

Here's the structure of my /var/www:这是我的 /var/www 的结构:

webApp
   webApp
      static
      templates
      __init__.py
   webapp.wsgi

My webapp.wsgi file:我的 webapp.wsgi 文件:

#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/webApp/")

from webApp import app as application
application.secret_key = 'Add your secret key'

My webApp.conf file:我的 webApp.conf 文件:

<VirtualHost *:80>
    ServerName my_vps_ip
    ServerAdmin email@mywebsite.com
    WSGIScriptAlias / /var/www/webApp/webapp.wsgi
    <Directory /var/www/webApp/webApp/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/webApp/webApp/static
    <Directory /var/www/webApp/webApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And finally, my __init__.py file:最后,我的__init__.py文件:

from flask import Flask

app = Flask(__name__)
@app.route('/', methods = ['GET'])
def test():
    return 'test'

if __name__ == '__main__':
    app.run()

And this happens when I visit the server ip:当我访问服务器 ip 时会发生这种情况:

Why could this be happening?为什么会发生这种情况? I've spent all day trying to figure this out, so any help is appreciated!我花了一整天的时间试图弄清楚这一点,所以任何帮助表示赞赏!

Can You please check the serverName is correct and should be a registered domain.你能检查一下 serverName 是否正确,应该是一个注册的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM