11

Amazon S3 でホストされているウェブページがありますが、http 応答コードを200. このページは、メンテナンスのためにメイン Web サイトを停止するときにトラフィックをリダイレクトするメンテナンス ページです。

Amazon S3 ページに次の応答ヘッダーを含めたい:

HTTP/1.1 503 Service unavailable

Amazon は S3 オブジェクトにいくつかのメタデータを追加する機能を提供しますが、http ステータス コードには何もありません。

出来ますか?

4

4 に答える 4

2

Cloudfront でこれを行うことができると思います。まだテストしていませんが、これを試してください:

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/custom-error-pages.html

于 2014-06-19T14:40:01.310 に答える
-1

Amazon が S3 からのカスタム ステータス コードを許可するまでは、nginx を使用した回避策があります。

メンテナンス モードの「オン スイッチ」として機能する特定のファイルの存在を監視します。見つかった場合は、proxy_passS3 にリクエストします。秘訣は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;
    }
}
于 2015-09-18T12:50:50.323 に答える