我们有一个NGINX反向代理(集群),有45个上游(22个域名,20个子域名,11个应用程序)。
我们的一些项目为全球的一些用户提供apis。
我们的开发人员为特殊情况devise了特殊的自定义500响应,并希望只显示上游tomcat_api的消息。
他们想要服务500页,并处理不在NGINX上的tomcat_api上游成员的exception。 但是我们想要处理NGINX上所有其他的5xx错误。
因为我现在不能成功需要一个手。
这里是服务器configuration如下,请你帮忙?
服务器{
server_name api.hotcoldwarm.com;
位置 / {
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection“1; mode = block”;
add_header x-redirect-uri hotcoldwarm;
add_header Strict-Transport-Security“max-age = 31536000; includeSubdomains; always”;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header主机$主机;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
proxy_pass http:// tomcat_api;
proxy_next_upstream错误超时http_502 http_503 http_504 http_404;
proxy_connect_timeout 1;
}
听80;
听443 ssl;
ssl_certificate /etc/rapidssl/live/api.hotcoldwarm.com/fullchain.pem;
ssl_certificate_key /etc/rapidssl/live/api.hotcoldwarm.com/privkey.pem;
包括/etc/rapidssl/options-ssl-nginx.conf;
if($ scheme!=“https”){
返回301 https:// $ host $ request_uri;
}
}
谢谢。
你可能想考虑proxy_intercept_errors on; 选项。 然后在它后面configuration自定义的error_page 。 请参阅回答https://stackoverflow.com/a/8715597/434255