skip to Main Content

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


  1. 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 "/".

    Login or Signup to reply.
  2. It’s obvious that we can’t do this directly with AWS Route53.

    We can do it by other methods like:

    1. Cloudfront with 2 origins and respective behaviors.

    2. 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:

    • Create Distribution with amplify endpoint as the origin.
      create cf distribution
    • Create an additional origin with your ec2 endpoints and name it marketing
      create origin for marketing site
    • Create new behaviour with the custom path (replace /test with your path), and new origin marketing
      • use wildcard /test/* if you want all the sub path requests into new domain
        create behaviour for specific path
    • Then wait for it to deploy
    • Now all your requests will be forwarded to the default domain (amplify), except the custom path /test in this case, and /test/ requests will be forwarded to marketing site.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search