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

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;

修改后测试通过

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-12-23
  • 2021-09-09
猜你喜欢
  • 2021-06-27
  • 2021-09-23
  • 2021-07-23
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案