1、自定一个页面,这个页面是一个链接地址可以直接访问的。

以下是nginx的配置:

location / {
            proxy_pass http://tomcat_app108;
            #client_max_body_size 1000m;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            error_page  502 503 504  http://www.cbd.com;
            index   index.html;
        }

注:当出现50x的错误的时候,域名会发生变化,会跳转到这个 http://www.cbd.com域名上去

2、自定义一个页面,当发生50x的错误的时候,域名不变

以下是nginx配置:

location / {
            proxy_pass http://tomcat_app108;
            #client_max_body_size 1000m;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            error_page  502 503 504  /tips;
            index   tips.html index.html;

       location  /tips {
               root  /opt/www/test/;
                index   tips.html;
        }

注:当发生50x的错误的时候,会去寻找/tips的信息,然后匹配到下面location  /tips这个location的内容,跟着会去到这个/opt/www/test/目录下寻找相关页面,这个目录下面有tips这个目录,tips目录下面有tips.html这个文件,这样一步一步就能找到自定义的错误页面了

比如域名是www.cbd.com,访问一下www.cbd.com/tips如果能访问到错误页面说明配置没有问题;

验证:当服务器端发生500,502,503错误时候,会自动跳转到www.cbd.com/tips

注意:若发生错误没有跳转,需要详细看一下一个参数:

proxy_intercept_errors on;

当上游服务器响应头回来后,可以根据响应状态码的值进行拦截错误处理,与error_page 指令相互结合。用在访问上游服务器出现错误的情况下。

以下是完整的配置:

location / {
            proxy_pass http://tomcat_app108;
            #client_max_body_size 1000m;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_intercept_errors on;

error_page  502 503 504  /tips;
            index   tips.html index.html;

       location  /tips {
               root  /opt/www/test/;
                index   tips.html;
        }

转自:

nginx自定义500,502,504错误页面无法跳转-布布扣移动版-m.bubuko.com
http://m.bubuko.com/infodetail-1933746.html

nginx自定义500,502,504错误页面无法跳转【转】的更多相关文章

  1. Nginx的500,502,504错误解决方法

    Nginx的500,502,504错误解决方法 一.解决500错误: 1.500错误指的是服务器内部错误,也就是服务器遇到意外情况,而无法履行请求. 2.500错误一般有几种情况: (1)web脚本错 ...

  2. http的500,502,504错误

    500 500的错误通常是由于服务器上代码出错或者是抛出了异常 解决方法:查看一下对应的代码是不是有问题. 502 502即 Bad Gateway网关(这里的网关是指CGI,即通用网关接口,从名字就 ...

  3. lnmp 在nginx中配置相应的错误页面error_page

    1. 创建自己的404.html页面 2.更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on; 3.更改nginx.conf(或单独网站配置文件, ...

  4. http协议的状态码 403 404 301 302 200 500 502 504 报错显示

    在网站建设的实际应用中,容易出现很多小小的失误,就像MySQL当初优化不到位,影响整体网站的浏览效果一样,其实,网站的常规http状态码的表现也是一样,Google无法验证网站几种解决办法,提及到由于 ...

  5. asp.net core 自定义404等友好错误页面

    Home控制器里: [Route("Home/Error/{statusCode}")] public IActionResult Error(int statusCode) { ...

  6. nginx配置设置,使部分页面访问跳转到404页面

    location ~* /(ask|hospital|wenda|regsearch|user|doctor) { return ; } error_page /.html;

  7. nginx下配置404错误页面

    1.创建自己的404.html页面,并放于网站根目录. 2.更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on; 3.更改nginx.conf(或 ...

  8. NGINX下配置404错误页面的方法分享

    NGINX下配置自定义的404页面是可行的,而且很简单,只需如下几步,需要的朋友可以参考下   1. 创建自己的404.html页面 2.更改nginx.conf在http定义区域加入: fastcg ...

  9. Nginx配置error_page 404错误页面

    问题由来 昨天一网友在segmentfault.com上提问,无法做404重定向 打开对方的网站随便输入一个错误的地址发现给出了404代码,但是页面完全空白,并没有显示404页面的设定内容 当时就明白 ...

随机推荐

  1. django中使用FastDFS分布式文件系统接口代码实现文件上传、下载、更新、删除

    运维使用docker部署好之后FastDFS分布式文件系统之后,提供给我接口如下: fastdfs tracker 192.168.1.216 192.168.1.217 storage 192.16 ...

  2. 【ARC074e】RGB sequence

    Description ​ 一排\(n\)个格子,每个格子可以涂三种颜色的一种.现在给出\(m\)个形如"\([l,r]\)中必须恰好有\(x\)种颜色"的限制(\(1 \le l ...

  3. 【poj2127】 Greatest Common Increasing Subsequence

    http://poj.org/problem?id=2127 (题目链接) 题意 计算两个序列$a$和&b$的最长公共上升子序列. Solution 爸爸的$n^3$算法莫名其妙RE了,不爽之 ...

  4. All flavors must now belong to a named flavor dimension

    FAQ: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/ ...

  5. [APIO2009]采油区域

    题目描述 Siruseri 政府决定将石油资源丰富的 Navalur 省的土地拍卖给私人承包商以 建立油井.被拍卖的整块土地为一个矩形区域,被划分为 M×N 个小块. Siruseri 地质调查局有关 ...

  6. L. Twice Equation ACM Nanning 2017

    https://nanti.jisuanke.com/t/19978 acm提交:类 Main 使用java:高精度 BigInteger import java.math.BigInteger; i ...

  7. c/c++基本数据类型转换

    If either operand is of type long double, the other operand is converted to type long double. If the ...

  8. lumen passport Call to undefined method Laravel\Lumen\Application::group()

    解决方法:https://github.com/dusterio/lumen-passport/issues/69 public function boot() { LumenPassport::ro ...

  9. supervisor 添加新配置不生效的问题

    supervisorctl reread supervisorctl reload (不运行这一步会导致启动不了) supervisorctl start xxx:* 提示:No config upd ...

  10. chrome神插件之:SwitchyOmega的安装设置

    转至:http://yiweifen.com/v-1-118586.html 前言 往常找某草的网站基本上是这样的:先FQ,然后谷歌找1024,出现很多某草的更新地址,大多都是广告,大约需要花十几分钟 ...