error_page 502 =200 /my_return;
location /my_return {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods GET,POST;
set $ret_body '{"code": 502, "msg": "系统正在启动"}';
return 200 $ret_body;
}
解释:
# 将502状态码转换为200,重定向到/my_return
error_page 502 =200 /my_return;
# 允许跨域,如果配置在单个匹配中,就是允许该请求跨域
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Methods GET,POST;
# 设置自定义json信息返回
set $ret_body '{"code": 502, "msg": "系统正在启动"}';
return 200 $ret_body;
Nginx 502状态码自定义返回json信息
nginx