AWS Cloud Front, how to request origin using correct url

Solution 1:

There are several ways to do that:

Set the headers X-Forwarded-Host & X-Forwarded-Proto within Cloudfront configuration for origin requests to pass the required information to the backend application. On the backend use the Headers, if present, for generating the content within the pages.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto

Another approach could be to setup a lambda@edge that processes the origin response, and replaces the content where needed.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-updating-http-responses.html