My setup is as follows:
All this is perfectly what I want, HOWEVER .....
The reason is because EC2 see the request coming from the load balancer so it assumes the base url is elb.example.com and generates all links accordingly.
How do make EC2 see the base url as example.com ?
Sign in to the AWS Management Console and open the CloudFront console at https://console.aws.amazon.com/cloudfront/v3/home . Choose the ID for the distribution that you want to update. On the General tab, choose Edit. Add your alternate domain names.
This behavior likely results from the fact that by default CloudFront sets the Host:
HTTP request header to the origin hostname, in this case elb.example.com. The application then presumably generates links based on that hostname.
If, instead, you configure CloudFront to whitelist that header for forwarding to the origin, the Host header sent by the browser (example.com) will be sent on to the application by CloudFront, so the application should behave more like you'd expect and use that value when generating the links. With this, CloudFront still uses the origin domain name to do the DNS lookup needed in order to establish the TCP connection to the origin (the ELB in this case), but stops injecting that hostname into the HTTP request headers.
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesForwardHeaders
You'll find the host header under cache behavior settings -> cache based on selected request headers -> whitelist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With