显示自定义页面503,如果上游下来 [英] Show a custom 503 page if upstream is down
问题描述
我使用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 areturn
keyword
For example:# check for a condition if (condition) { return 503; }
Also See
nginx: Create HTTP 503 Maintenance Custom Page这篇关于显示自定义页面503,如果上游下来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!