LoginSignup
0
0

More than 1 year has passed since last update.

S3の静的ウェブサイトで複数のサブフォルダーをホストする

Last updated at Posted at 2021-10-17

やりたいこと

S3バケットに複数のサブフォルダーを追加して、https://domain_name/folder_nameでそれぞれのフォルダーにアクセスできるようにする

目次

  1. 設定
  2. エラー
  3. 参考文献

1. 設定

S3バケットにサブフォルダーを追加する

BUCKET_NAME/portfolio
BUCKET_NAME/website_1
BUCKET_NAME/website_2

それぞれのサブフォルダーにドキュメントルートとしてindex.htmlを設置

BUCKET_NAME/portfolio/index.html
BUCKET_NAME/website_1/index.html
BUCKET_NAME/website_2/index.html

CloudFrontディストリビューションの設定を変更

対象のディストリビューションを選択して、Error pagesタブへ移動
カスタムエラーレスポンスを作成
  1. エラーコード403を選択
  2. response page pathindex.htmlに設定
  3. 作成 Screen Shot 2021-10-17 at 10.33.00.png Screen Shot 2021-10-17 at 10.30.43.png
動作確認

ディストリビューションがデプロイされたら、https://domain_name/folder_nameでアクセスをしてエラーが出なければ完了

2. エラー

上記の設定をしても、403エラーのリダイレクトがされない場合に確認すること
CloudFrontディストリビューションのorigin nameはS3静的ウェブサイトのエンドポイントを設定する

⭕️BUCKET_NAME.s3-website-ap-southeast-1.amazonaws.com

origin nameがS3バケットそのもののエンドポイントだとリダイレクトがうまくいかない
BUCKET_NAME.s3.ap-southeast-1.amazonaws.com

コメント

ベストプラクティスではないかもしれないけれど、個人や社内のトレーニング用で複数のウェブサイトを一つのバケットで管理したいときに便利だと思った

3. 参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0