nginx自定义404页面


主要是记录踩过的一个坑。。。

nginx要自定义404和500的页面,但是error_page 配置没有生效,没有正常跳转。

error_page  404  /404.html;
error_page  500 503 502  /500.html;
location = /500.html {    
            root html;
        }
location = /404.html {
            root html;
        }

这是因为我们的静态资源在上游服务器上,而不是当前nginx直接提供。

 

nginx proxy 启用自定义错误页面:

语法:proxy_intercept_errors on | off;

默认值:

proxy_intercept_errors off;

上下文:http, server, location

当被代理的后端服务器的响应状态码大于等于300时,决定是否直接将响应发送给客户端,亦或将响应转发给nginx由error_page指令来处理。

 proxy_intercept_errors 为on 表示 nginx按照原response code 输出,后端是404就是404。这个变量开启后,我们才能自定义错误页面。

proxy_intercept_errors on;

修改后测试通过


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM