configure-nginx-how-to-handle-500-error-on-upstream-itself-while-nginx-handle 自定义header 传递header 定义拦截器

 应用程序拦截

 

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/;
        }
    }

  

 

posted @ 2019-10-30 12:43  papering  阅读(247)  评论(0编辑  收藏  举报