nginx + uwsgi + flask - disabling custom error pages

后端 未结 3 1629
-上瘾入骨i
-上瘾入骨i 2021-01-11 20:09

Is it possible to disable nginx\'s custom error pages - if I may call them that - to display my framework\'s exception pages?

I can\'t really see my werkzeug debugge

3条回答
  •  春和景丽
    2021-01-11 21:14

    Simon Sapin has really given you the correct answer. You need to enable debug in Flask. Nginx does not return any custom error pages unless you explictly configure it to do so.

    If you use the following code you will see your debug messages from flask, proxied via Nginx.

    from flask import Flask
    
    app = Flask(__name__)
    app.debug = True
    
    @app.route('/')
    def index():
        raise Exception()
    

    As per your update 2. You are seeing a 502 (bad gateway) because Flask is simply not returning any response at all, or a response that Nginx does not understand. A 502 is not a problem with Nginx. It means that whatever Nginx is trying to talk (your flask app in this case) is not working properly at all.

    However, in many ways you shouldn't be doing this. Debugging mode should only be enabled when you are running flask on your local dev machine. Which is the whole point of the if __name__ == "__main__": line anyway.

提交回复
热议问题