How to correctly set up Amazon Route 53, CloudFront with custom origin
OK so this is how I managed to solve it in the end:
Origin Server:
- In cPanel (on my origin server) I created a sub-domain called
origin.domain.com
origin.domain.com
shares the same document root asdomain.com
- My .htaccess file redirects
domain.com
towww.domain.com
:
Amazon CloudFront:
The "Alternate Domain Names (CNAMEs)" is set to
www.domain.com
The origin is set to
origin.domain.com
Amazon Route 53
The A record for
domain.com
is set to my origin server's IP addressThe A record for
www.domain.com
is set to an alias for the CloudFront distributionorigin.domain.com
is a CNAME fordomain.com
Thanks to Matt Houser and Bruce P for their help, by the way. :)
Assuming your have your origin at origin.domain.com
, create your CloudFront distribution, using http://origin.domain.com as the origin.
Create your www.domain.com
DNS entry in Route 53, making it an "Alias" for the CloudFront distribution.
One possible alternative to .htaccess is to use WAF on your CloudFront distribution. This way, you can permit/deny based on IP address.