2011年2月19日

Amazon S3で静的なWebサイトをホスティングする方法

昨日、Amazonからこんなメールが送られて来た。

Dear Amazon S3 Customer,

We're excited to announce new features that make it easy to host static websites on Amazon S3. Customers already use Amazon S3 to host images, video, and other content for their websites, but until now they haven't been able to effectively host their entire website on Amazon S3. That's because even though customers can configure an Amazon S3 bucket as a website, users accessing the root of the website (e.g. http://www.mywebsite.com/) would see the list of objects in the Amazon S3 bucket instead of the website's home page. Also, if an error occurred, users would see an Amazon S3 error message instead of a website specific error message. In response to customer requests, we've added support for root and custom error documents to address these issues.
(...)

Amazon S3を使って静的なWebサイトを簡単にホストする為の新機能についてお知らせします。既にS3で画像や動画その他のコンテンツをホストしてWebサイトから利用されているお客様はおられますが、今まではサイト全体を効果的にホスティングする事は出来ませでした。その理由は、Amazon S3のBucketをWebサイトとして設定する事は出来ても、そのサイトのルート(例: http://www.mywebsite.com/)にアクセスしたユーザーにはBucket内のオブジェクトの一覧が表示されてしまうからです。また、もしエラーが起きた場合は、Webサイトに特化したエラーメッセージではなくAmazon S3のエラーメッセージが表示されます。お客様からの要望にお答えして、これらの問題に対処する為にルートドキュメントおよびカスタムエラーメッセージのサポートを追加しました。
(略)

Sincerely,
The Amazon S3 Team

との事なので、早速久しぶりにS3を使って見た。

管理画面からBucketを作成。

Bucketのプロパティを開いてパーミッションタブで公開範囲を設定し、WebSiteタブでWebサイトとしてアクセス可能にするかどうか、Indexページのファイル名、エラーページのファイル名を指定する。

Bucketにindexページとエラーページ、画像ファイルとCSSやScriptのフォルダなどをアップロード。
今回はテスト用に自分のWebサイトからコピーして見る。

BucketのURLをブラウザで開くと...表示された!

「静的なWebサイト」と言っても、サーバー側が静的なだけでもちろんクライアント側ではAjaxで色々する事は出来るので、使い方によっては重宝するのではないだろうか。

あるいは、通常のWebサーバーが落ちた時など、緊急時のバックアップ用とかにも良いと思う。











.