アップストリームがダウンしている場合は、カスタム503ページを表示します
-
14-11-2019 - |
質問
NginxをApacheサーバーにフロントエンドとして使用しています。設定ファイルは次のようになります。
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/;
}
}
.
今のところ、Apacheが停止しているとき、私はNginxによって生成された平文502ページを受け取ります。この状況でより関連性があるカスタムエラーページと返品状況コード503を提供する方法は?
解決
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;
}
所属していません StackOverflow