I have a domain abc.io
in my Route 53.
I have a nextJS application in AWS amplify.
I have my marketing website on the EC2 server.
I wanted abc.io
to open my nextJS application whereas abc.io/w/*
opens the marketing website.
How can I configure my AWS to achieve that?
2
Answers
Use CloudFront. Create a CloudFront distribution with two behaviors and two origins. First, create two origins with one pointing at the marketing website and one pointing at the NextJS application. Next, you’ll need to direct traffic to these origins with Behaviors. The first behavior should be for /w/* and point traffic to your marketing website origin. The second behavior should be for /* and point traffic to your NextJS app.
Then point your domain at CloudFront: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-cloudfront-distribution.html
When you are done, Route53 will point to CloudFront. CloudFront will handle routing requests to the two origins based on the path in the request. You can even modify the request path to make it appear to the marketing website that requests to "/w/" are being passed to "/".
It’s obvious that we can’t do this directly with AWS Route53.
We can do it by other methods like:
Cloudfront with 2 origins and respective behaviors.
Custom nginx server to manage this, but for this, we need to configure SSL separately, either using self-signing or using some sort of proxying with the load balancer.
Cloudfront Approach:
marketing
/test
with your path), and new originmarketing
/test/*
if you want all the sub path requests into new domain/test
in this case, and/test/
requests will be forwarded to marketing site.