zoukankan      html  css  js  c++  java
  • 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;

    修改后测试通过

  • 相关阅读:
    Transformation
    Yet Another Number Sequence
    Table
    K个联通块
    Acyclic Organic Compounds
    Sandy and Nuts
    tetrahedron
    BZOJ4750 密码安全
    实现商品秒杀 时间倒计时
    实现qq登录
  • 原文地址:https://www.cnblogs.com/xulan0922/p/9224260.html
Copyright © 2011-2022 走看看