nginx tomcat 404 页面跳转

今天业务需求需要把所有的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;

default:

fastcgi_intercept_errors off;

context:http, server, location

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,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值