AWS S3 Static Hosting with CloudFront and Directory Forwarding

My problem is not only about hosting a static website on S3, but to a much lesser extent.

My plan is to have www.foo.com on the S3 website.

So, I create a bucket with the name www.foo.com, and I set the domain there.

Thus, every file that I have on my bucket is publicly accessible and is part of the website.

But there is one exception:

  • Whenever I go to www.foo.com/blog, I want to do an internal redirect to a blog hosted in an EC2 container.

This would be easily achievable with Nginx with a definition proxy_pass. But S3 is not Nginx.

I know that there are some redirect rules that I can apply, but how would I go about doing an internal redirect, where the user has the URL http://www.foo.com/blog , but the blog is hosted on a different machine.

+4
source share
1 answer

Since you mentioned that you are using CloudFront, you want to use this for redirection instead of S3. You would configure two sources in your CloudFront distribution, your S3 bucket and EC2 server. You would configure S3 as the default source and create a cache behavior with the / blog template that points to the source of EC2.

+3
source

Source: https://habr.com/ru/post/1665328/


All Articles