S3をバックにEC2をリバースプロキシにする
最近、自分のテスト環境用にSSLサーバ証明書を買ったついでにEC2をリバースプロキシ、S3をバックエンドにした構成を整理してみた。
サーバの構成イメージは以下のような感じ。
コンテンツはS3に置きたいし、カスタムドメインでSSLを使いたいって場合の構成。
環境がVPCであることは単純な私の好みなのでお気になさらずに。
S3設定
- S3バケットのWebサイト機能を有効化(indexドキュメントとerrorドキュメントを配置)
- EC2からしかアクセス出来ないようにBucket Policyを設定(必須ではない)
EC2のApacheに行う設定
mod_rewriteを使った場合
# Reverse Proxy RewriteEngine On RewriteRule ^.*$ http://fuga.s3-website-ap-northeast-1.amazonaws.com/$1 [P,L] # Cache CacheRoot /tmp/cache CacheIgnoreCacheControl off CacheEnable disk / CacheMinFileSize 0 CacheMaxFileSize 128000 CacheDirLevels 5 CacheDirLength 3
mod_proxyを使った場合
# Reverse Proxy ProxyPass / http://fuga.s3-website-ap-northeast-1.amazonaws.com/ ProxyPassReverse / http://fuga.s3-website-ap-northeast-1.amazonaws.com/ # Cache CacheRoot /tmp/cache CacheIgnoreCacheControl off CacheEnable disk / CacheMinFileSize 0 CacheMaxFileSize 128000 CacheDirLevels 5 CacheDirLength 3