今天业务需求需要把所有的404页面都跳转到一个固定页面,下面说下我的生产环境
Nginx+Tomcat实现反向代理,当Client请求某个action的时候如果tomcat抛出404,那么就指定nginx访问到一个首页。
使用反向代理的生产环境需要使用下面这个参数
在server段中加如下参数
proxy_intercept_errors on
语法:proxy_intercept_errors |关闭;
默认值:
proxy_intercept_errors;
上下文:http服务器的位置
当被代理的后端服务器的响应状态码大于等于300时,决定是否直接将响应发送给客户端,亦或将响应转发给nginx由error_page指令来处理。
原文:
syntax:proxy_intercept_errors on | off;
default:
proxy_intercept_errors off;
context:http, server, location
Determines whether proxied responses with codes greater than or equal to 300 should be passed to a client or be redirected to nginx for processing with the error_page directive.
proxy_intercept_errors 为on 表示 nginx按照原response code 输出,后端是404,就是404.这个变量开启后,我们才能自定义错误页面。
nginx配置文件代码:
语法:fastcgi_intercept_errors on | off;
fastcgi_intercept_errors off;
上下文:http, server, location
当FastCGI后端服务器响应状态码大于等于300时,决定是否直接将响应发送给后端客户端,或者将响应转发给nginx由 error_page指令来处理。
syntax:fastcgi_intercept_errors on | off;
Determines whether FastCGI server responses with codes greater than or equal to 300 should be passed to a client or be redirected to nginx for processing with the error_page directive.
fastcgi_intercept_errors on表示接收fastcgi输出的http 1.0 response code,后端php可以输出header指示nginx输出什么错误页面。开启这个之后,我们才能在php里面自定义错误代码和页面。
必须明确的在error_page中指定处理方法使这个参数有效,如果没有适当的处理方法,nginx不会拦截一个错误,这个错误不会显示自己的默认页面,这里允许通过某些方法拦截错误。
本文转自 xinsir999 51CTO博客,原文链接:http://blog.51cto.com/xinsir/1956550,如需转载请自行联系原作者