As you may already see that all static files (CSS, JavaScript and image files) in my blogs are delivering from CDN via 3 sub domains: cdn, cdn1 and cdn2 and all those files are still hosted on my own dedicated server. Meaning you can either access a particular file from my main domain or from a certain CDN domain (cdn, cdn1 or cdn2).
For example, 2 image link below will load the same content, one from the Amazon CDN and one from my own server:
+ http://cdn.4rapiddev.com/wp-content/uploads/2011/12/WP-Super-Cache-CDN-Settings.jpg
+ http://4rapiddev.com/wp-content/uploads/2011/12/WP-Super-Cache-CDN-Settings.jpg
This post will let you know steps by steps how I set it up.
First, you need to Sign up for Amazon CloudFront service via: http://aws.amazon.com/cloudfront/. Once you have verified your account and activated your CloudFront service, please follow steps below:
CloudFront Loads Original Files From Custom Sub Domain
Meaning you intend to use your own server to host original files and these files will be accessed through CDN via your own domain or sub domain.
- 1. Login to the AWS Management Console then click on Amazon CloudFront tab.
- 2. Create a new Distribution by clicking on Create Distribution button. In the Create Distribution Wizard, select Custom Origin option then type your domain which will associate with the distribution in Origin DNS Name text box. Ex: 4rapiddev.com. After that, click Continue button to go to the next step.
Note: this is the first requirement of this tutorial: storing files on your own server. - 3. This is the second requirement, creating your own domains/sub domains that link to the distribution instead of using the CloudFront domain name. Simply enter desired domains in CNAMEs text box, ex: cdn.4rapiddev.com or cdn1.4rapiddev.com.
Note: you can enter up to 10 domains, separated by commas or new lines.
After everything is okay, click Continue button to review your new distribution settings. - 4. If you’re fine with current settings for the new Distribution, click Create Distribution button to finish this step or click Back to change something.
- 5. After clicking Create Distribution button, your distribution is created and appears in the list. However, it may take few minutes to propagate across the CloudFront system.
- 6. Creating CNAMEs (Alias) in your DNS control panel: cdn, cdn1 and cdn2 that point to Domain Name of your new distribution. In this case, the domain name is d1415bowm1j0qn.cloudfront.net and assume that we’re trying to create CNAME in Godaddy DNS Manager. These CNAMEs also need few minutes to be propagated across DNS servers.
That’s all. Now you can access static files either from your own domain URL or from CNAMEs you just create or even from CloudFront domain name as long as they have the same structure and your distribution is Deployed.
For example:
+ http://4rapiddev.com/wp-content/uploads/2011/12/AWS-Management-Console-Amazon-CloudFront.jpg
+ http://d1415bowm1j0qn.cloudfront.net/wp-content/uploads/2011/12/AWS-Management-Console-Amazon-CloudFront.jpg
+ http://cdn.4rapiddev.com/wp-content/uploads/2011/12/AWS-Management-Console-Amazon-CloudFront.jpg
+ http://cdn1.4rapiddev.com/wp-content/uploads/2011/12/AWS-Management-Console-Amazon-CloudFront.jpg
+ http://cdn2.4rapiddev.com/wp-content/uploads/2011/12/AWS-Management-Console-Amazon-CloudFront.jpg