显示自定义页面503,如果上游下来 [英] Show a custom 503 page if upstream is down

查看:253
本文介绍了显示自定义页面503,如果上游下来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用nginx的作为前端Apache服务器。配置文件如下:

 上游阿帕奇{
    服务器localhost:8000;
}服务器{
    听80;
    error_page 503 /www/static/503.html;    #在这里需要一些魔术#    位置/静态/ {
        根/ WWW /静态/;
    }    位置 / {
        proxy_path HTTP://阿帕奇/;
    }
}

现在,当Apache下跌,我收到nginx的产生一个普通的502页。如何使它为我的自定义错误页,并返回状态code 503这是在这种情况下更相关?


解决方案

像这样

 上游阿帕奇{
    服务器localhost:8000;
}服务器{
    听80;
    error_page 502 503 /www/static/503.html;    位置/静态/ {
        根/ WWW /静态/;
    }    位置 / {
        proxy_path HTTP://阿帕奇/;
    }
}

您可以附加标准错误codeS一起为几种类型的错误显示一个页面。结果
例如:

  error_page 502 503 /www/static/503.html;

有关更多的参考,你可以参考 error_page手动


error_page手动它说:


  

此外,可以改变
  答案的code到另一个,为
  例如:


  error_page 404 = 200 /.empty.gif;


另一种选择的结果
为了使返回不同的错误code,你可以使用的收益关键字搜索
例如:

 一个条件#检查
  如果(条件){
     返回503;
  }

另请参见的结果
nginx的:创建HTTP 503维护自定义页面

I am using nginx as a frontend to an apache server. The config file looks like:

upstream apache {
    server localhost:8000;
}

server {
    listen 80;
    error_page 503 /www/static/503.html;

    # need some magic here #

    location /static/ {
        root /www/static/;
    }

    location / {
        proxy_path http://apache/;
    }
}

For now, when apache is down, I receive a plain 502 page generated by nginx. How to make it serve my custom error page and return status code 503 which is more relevant in this situation?

解决方案

Something like this

upstream apache {
    server localhost:8000;
}

server {
    listen 80;
    error_page 502 503 /www/static/503.html;

    location /static/ {
        root /www/static/;
    }

    location / {
        proxy_path http://apache/;
    }
}

You can append standard error codes together to display a single page for several types of errors.
For example:

error_page 502 503 /www/static/503.html;

For more reference you can refer the error_page manual


On the error_page manual it says

Furthermore, it is possible to change the code of answer to another, for example:

error_page 404 =200 /.empty.gif;


Another option
To make it return a different error code you can make use of a return keyword
For example:

# check for a condition
  if (condition) {
     return 503;
  }

Also See
nginx: Create HTTP 503 Maintenance Custom Page

这篇关于显示自定义页面503,如果上游下来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆