How to redirect http requests to S3 bucket using Apache

S3 bucket is the cloud storage service in AWS and we can use the same for static website hosting. The S3 bucket need to be configured with public access in this case.

Here we are discussing the configuration of an application hosted in EC2 need to fetch the static content hosted on S3 bucket. Note that Apache is the web server configured in EC2 instance.

So we need to add the following lines to the virtual host configuration of Apache.

ProxyPassMatch  /path(.*) http://S3url/folder$1
ProxyPassReverse /path(.*) http://s3url/folder$1


path need to be replaced with the exact uri that we need to redirect.
s3url need to be replaced with the exact web url for corresponding s3 bucket.
folder need to be replaces with the folder in s3 bucket where the static content hosted. This can be ignored if there is no subfolder.

Since there is a configur change in Apache, the service need to be restarted and after that it will start redirecing those specific connections to s3 bucket.

That's all…

Leave a Reply