How can I serve a static site on S3/CloudFront and an API from an EC2 instance via Nginx(only ec2) under the same domain?

Requests to my.domain should serve the static site hosted on S3 via CloudFront, while requests to my.domain/api should be routed to the API hosted on an EC2 instance.

I tried configuring my CloudFront distribution to serve both a static site hosted on an S3 bucket and an API hosted on an EC2 instance under the same domain. I expected that requests to the root domain (my.domain) would be routed to the S3 bucket via CloudFront, and requests to the /api path would be routed to the EC2 instance. However, the routing did not work as expected, and all requests were either going to the S3 bucket or returning an error.

0

There are 0 best solutions below