Currently I have my webserver at mydomain.com and two CDNs at static.mydomain.com and media.mydomain.com.
Would it be possible to have all under mydomain.com? e.g.
mydomain.com - webserver
mydomain.com/static - static CDN
mydomain.com/media - media CDN
This configuration should be possible using a combination of Route 53's alias feature, S3 redirects and CloudFront behaviors.
1 Configuring a CloudFront distribution with multiple origins and path matching behaviors
It looks like you have three different content origins, the 'webserver' content, the 'static' content, and the 'media' content. CloudFront should be able to serve the content for each of these origins behind the same domain name. To set this up you'll need to configure three different origins within your CloudFront distribution. Here's a guide to creating a CloudFront distribution, and I've provided an overview below: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreatingDownloadDistributions.html
2 Configure CloudFront to work with your domain name
When you create a CloudFront distribution you are issued a distribution name under the 'cloudfront.net' domain. In order for CloudFront to work in conjunction with your own domain name, you'll need to configure a CNAME that points 'www.mydomain.com' domain to the CloudFront distribution DNS name. Then you'll need to configure your CloudFront distribution to respond when it sees requests for the www.mydomain.com domain.
Docs: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html
At this point, when you browse to www.mydomain.com, you'll be routed to the nearest CloudFront edge location, and the content returned will come from one of three different content origins based on the path of the request. But you'd also like 'mydomain.com' to behave the same way. You can achieve this by creating a www-lyzer with Route 53 Aliases and S3 redirects.
3 Creating a www-a-lizer at the zone apex of 'mydomain.com' with Route 53 alias and S3 redirects
This blog post provides a pretty good walk through of Route 53 Alias and S3 redirects, for this example we'll need to make a couple of adjustments called out in the steps below:
http://aws.typepad.com/aws/2012/12/root-domain-website-hosting-for-amazon-s3.html
<RoutingRules> <RoutingRule> <Redirect> <HostName>www.mydomain.com</HostName> </Redirect> </RoutingRule> </RoutingRules>
Name: 'mydomain.com'
Type: 'A'
Alias: 'Yes'
Response to the comment:
The goal of the third step is to ensure that requests to 'mydomain.com' are directed through the CloudFront distribution. Ideally, we'd be able to use CNAMEs as outlined in step 2, however CNAMEs can't be used at the zone apex. For the time being this means we have to jump through some hoops.
It is possible to use expanded redirection rules within S3 to redirect to different origins based on path matching. That would mean all of your user's requests would hit S3 before redirecting to the CDN or directly to your origin. That would add a bit more latency to each request. To get the best performance from the CDN, you'll want your users to connect as directly as possible (ideally with no redirects). The solution proposed above counts on the fact that redirection happens only one time (when the user request 'mydomain.com'), and all subsequent user requests go directly to 'www.mydomain.com'.
As for POST and authentication via CloudFront. CloudFront will pass back cookies and query strings to the origin, if its configured to do so. If your auth system can leverage either of these methods for token passing, you should be able to pass your auth requests through CloudFront. At this time, CloudFront does not passthrough POST requests to the origin. If you're using client-side script to POST, then you could POST around CloudFront using a different DNS name. e.g. 'post.www.mydomain.com'.
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