任何接?都是可能出错,4xx、5xx等 如果业务没有做好统?的错误管理,直接暴露给?户,?疑是看不懂 所以假如后端某个业务出错,nginx层也需要进?转换 让前端知道Http响应是200,其实是将错误的状态码定向?200,返回了全局兜底数据
server{
listen 80;
root /var/www;
index index.php;
location / {
proxy_pass http://lbs;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout http_503 non_idempotent;
proxy_intercept_errors on;
}
error_page 404 500 502 503 504 =200 /default_api;
location = /default_api {
default_type application/json;
return 200 '{"code":"-1","msg":"invoke fail, not found "}';
}
}
|