configure-nginx-how-to-handle-500-error-on-upstream-itself-while-nginx-handle

Posted rsapaper

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了configure-nginx-how-to-handle-500-error-on-upstream-itself-while-nginx-handle相关的知识,希望对你有一定的参考价值。

 应用程序拦截

 

nginx 拦截 保证 接口返回

 

https://serverfault.com/questions/859667/configure-nginx-how-to-handle-500-error-on-upstream-itself-while-nginx-handle

 proxy_intercept_errors

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors

 

    server {
        listen 8003 default_server;
        set $rip $remote_addr;
        set $x_request_trace_dump_this trace-id-host@$host-pid@$pid-connection@$connection-bytes_sent@$bytes_sent-msec@$msec-remote_addr@$rip;
        proxy_temp_file_write_size 102400k;
        location @fallback {
            return 500 \'{"status":500,"data":[],"msg":"please call admin..."}\';
        }
        location / {
            proxy_intercept_errors on;
            error_page 500 502 503 504 = @fallback;
            gzip on;
            gzip_proxied any;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Request-Trace-Dump $trace;
            if ($http_x_request_trace_dump = \'\') {
                set $x_request_trace_dump_that \'\';
            }
            set $x_request_trace_dump_that $http_x_request_trace_dump;
            set $trace $x_request_trace_dump_that@@$x_request_trace_dump_this;
            proxy_pass http://127.0.0.1:8004/;
        }
    }

  

 

以上是关于configure-nginx-how-to-handle-500-error-on-upstream-itself-while-nginx-handle的主要内容,如果未能解决你的问题,请参考以下文章