Search code examples
amazon-ec2amazon-web-servicesamazon-cloudfront

AWS: Cloudfront and EC2 on single domain


Is it possible to host mysite.com/ from ec2 and mysite.com/logo.gif from cloudfront?


Solution

  • No, you won't be able to make the part of the URL after the domain name influence the DNS lookup for mysite.com. However, if you're willing to settle for something like "images.mysite.com/logo.gif", you can easily resolve images.mysite.com to your CloudFront distribution using a CNAME.

    You could also configure the web server on your EC2 instance to redirect or proxy to CloudFront - but then your server is still getting hit every time that resource is loaded, which eliminates most of the benefit to using a CDN in the first place.