Amazon が S3 からのカスタム ステータス コードを許可するまでは、nginx を使用した回避策があります。
メンテナンス モードの「オン スイッチ」として機能する特定のファイルの存在を監視します。見つかった場合は、proxy_pass
S3 にリクエストします。秘訣はreturn 503
、503 ステータス コードの処理を nginx の「名前付きの場所」にリダイレクトすることです。
nginx conf ファイルの例 (関連するビットのみを示します):
server {
...
# Redirect processing of 503 status codes to a nginx "named location".
error_page 503 @maintenance;
# "Maintenance Mode" is off by default - Use a nginx variable to track state.
set $maintenance off;
# Switch on "Maintenance Mode" if a certain file exists.
if (-f /var/www/app/maintenanceON) {
set $maintenance on;
}
if ($maintenance = on) {
# For Maintenance mode Google recommend using status code: "503 Service unavailable".
return 503;
}
...
location @maintenance {
# Redirect the request to a static maintenance page hosted in Amazon S3.
# Note: Use proxy_pass instead of rewrite so we keep the 503 code (otherwise nginx serves a 302 code)
rewrite ^(.*)$ /index.html break;
proxy_pass http://bucketname.s3-website-us-east-1.amazonaws.com;
}
}