1

I have an angular site / web application example.com hosted on Amazon S3 as a static website. This s3 bucket serves as the origin for a cloudfront distribution and it works perfectly.

We have an additional requirement of deploying a blog for SEO purposes. I have wordpress instance which I mapped using DNS to blog.example.com

How can I make this www.example.com/blog?

  • All the links on the blog must redirect to www.example.com/blog instead of blog.example.com

  • The address bar should always be displayed as www.example.com/blog

  • All the guides I have gone through require the www.example.com to be hosted via Nginx or Apache. This has to be on S3 + cloudfront.

1 Answer 1

1

Easy enough.

CloudFront supports multiple origin servers, and uses path patterns to determine which origin server to forward the requests to... so multiple, independent backend systems, even systems that aren't inside AWS, can all "own" one or more paths under a single hostname, with one of them being the default and owning all the paths not explicitly configured.

This is probably similar to what you have read about Nginx or Apache (and can also be done with HAProxy and others), but the request routing is done by CloudFront, which connects to the appropriate back-end, sends the request, and returns (and possibly caches) the response.

It does not redirect, so the browser address bar never changes.

The caveats:

CloudFront won't strip paths, so /blog* routes requests to bloghost.example.com then bloghost has to have its content under the /blog path, not in the root of the site.

CloudFront forwards very few headers to the origin by default. You can configure it to forward what you need, but every header you forward will reduce your cache hit ratio. There are very sound reasons why this is true, though beyond the scope of this answer. You need to identify which headers wordpress needs, and whitelist them in CloudFront.

You will also need to configure CloudFront to forward query strings and cookies, since, again, it doesn't forward those by default.

See also:

https://stackoverflow.com/a/38709097/1695906

https://serverfault.com/a/729706/153161

https://stackoverflow.com/a/32364600/1695906

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.