nginx 为烧瓶中的未处理异常 500 错误提供 502
nginx gives 502 for non handled exception 500 error in flask
我是 运行 Flask 应用程序并使用 uwsgi socket nginx 配置。
这可能是一个愚蠢的问题,但我面临的问题是每当 Flask 代码中出现异常时(例如 1/0 未处理的异常),我的 nginx 给出 502 而不是 500。我想知道如果默认情况下引发异常没有从 uwsgi unix 套接字作为 500 传播到 nginx,还是我需要明确指定?我在某处读到,对于异常,Flask 不会自动引发 500 错误消息。任何评论都会有所帮助。谢谢。
查看 502 规范:
The HyperText Transfer Protocol 502 Bad Gateway server error response
code indicates that the server, while acting as a gateway or proxy,
received an invalid response from the upstream server.
如果您的应用在遇到异常时响应任何内容,很可能是垃圾,nginx 会(正确地)引发 502,这意味着 "I won't (as opposed to can't) talk to the backend"。
如果你想要 500s,你必须捕获任何可能的底层异常,将其包装在有效的响应中,然后由 nginx 处理。
终于解决了这个问题。感谢@Jeff Storey 和@joppich。
我的代理服务器无法读取导致此问题的后端服务器的响应。我添加了一个拦截器来捕获所有异常并使用 nginx proxy_intercept_errors on;
通过 uwsgi 将其传播到 NGINX。非常感谢 Jeff 和 joppich。感谢您的帮助。
我是 运行 Flask 应用程序并使用 uwsgi socket nginx 配置。
这可能是一个愚蠢的问题,但我面临的问题是每当 Flask 代码中出现异常时(例如 1/0 未处理的异常),我的 nginx 给出 502 而不是 500。我想知道如果默认情况下引发异常没有从 uwsgi unix 套接字作为 500 传播到 nginx,还是我需要明确指定?我在某处读到,对于异常,Flask 不会自动引发 500 错误消息。任何评论都会有所帮助。谢谢。
查看 502 规范:
The HyperText Transfer Protocol 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
如果您的应用在遇到异常时响应任何内容,很可能是垃圾,nginx 会(正确地)引发 502,这意味着 "I won't (as opposed to can't) talk to the backend"。
如果你想要 500s,你必须捕获任何可能的底层异常,将其包装在有效的响应中,然后由 nginx 处理。
终于解决了这个问题。感谢@Jeff Storey 和@joppich。
我的代理服务器无法读取导致此问题的后端服务器的响应。我添加了一个拦截器来捕获所有异常并使用 nginx proxy_intercept_errors on;
通过 uwsgi 将其传播到 NGINX。非常感谢 Jeff 和 joppich。感谢您的帮助。