我的nginx配置:location / { uwsgi_pass myapp; include uwsgi_params; uwsgi_buffering on; uwsgi_buffer_size 8k; uwsgi_connect_timeout 800; uwsgi_read_timeout 800; uwsgi_send_timeout 800; proxy_intercept_errors on; error_page 420 =444 @foo;}location @foo { return 444;}我尝试了可能想到的所有可能组合,包括/不带proxy_intercept_errors和error_page,但是无论我如何配置nginx,当我返回420 Enhance your calm(或任何其他错误代码,显然)时,它都会直接传递给客户. 此答案建议使用proxy_next_upstream,但这意味着使用proxy_pass而不是uwsgi_pass.我需要使用uwsgi_pass,因为我需要将某些参数传递给python应用.解决方案事实证明答案比我想象的要简单-使用 uwsgi_intercept_errors 指令.首先,从上游应用程序(在我的示例中为python)返回444.第二,按如下所示配置nginx:location / { uwsgi_pass myapp; include uwsgi_params; [...] uwsgi_intercept_errors on; error_page 444 @drop;}location @drop { return 444;}My app runs with nginx and uwsgi (python). My aim is to drop a connection (as explained here) e.g. when the python app decides to do so.Is there a nginx parameter to "intercept" upstream errors similar to proxy_intercept_errors? According to this answer, My nginx config:location / { uwsgi_pass myapp; include uwsgi_params; uwsgi_buffering on; uwsgi_buffer_size 8k; uwsgi_connect_timeout 800; uwsgi_read_timeout 800; uwsgi_send_timeout 800; proxy_intercept_errors on; error_page 420 =444 @foo;}location @foo { return 444;}I tried all possible combinations I could think of with/without proxy_intercept_errors and error_page but no matter how I configure nginx, when I return 420 Enhance your calm (or any other error code, apparently) it gets passed directly to the client.This answer suggests using proxy_next_upstream but that implies using proxy_pass rather than uwsgi_pass. I need to use uwsgi_pass because I need certain parameters passed to the python app. 解决方案 It turns out the answer is simpler than I thought - use the uwsgi_intercept_errors directive.Firstly, from the upstream app (in my case python) return 444.Secondly, configure nginx as follows:location / { uwsgi_pass myapp; include uwsgi_params; [...] uwsgi_intercept_errors on; error_page 444 @drop;}location @drop { return 444;} 这篇关于用nginx拦截上游错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 19:20