Content delivery networks (CDNs) can be extremely useful for a number of reasons, primarily because they provide end-users with faster load times, higher availability and more scalability. Unfortunately, they’re also a costly investment and necessarily add a lot of complexity to a website’s infrastructure.
There are ways around that, however. If you’ve read our article on “How to Use Content Delivery Networks,” you’ll have seen just how easy it is to turn the Google App Engine into a sort of makeshift CDN. But even if you don’t have a Google Apps account, you’ll still be able to create your own CDN with a CNAME.
Although these homemade CDNs aren’t going to perform quite as well as a professional solution, they’re still a great temporary fix to slow load times or downtime problems. However, if your website continues its growth even after applying your own CDN, it may be time to consider looking elsewhere.
But for now, keep reading for a step-by-step guide on how make your own content delivery network by setting up a CNAME record and creating an alias for your static domain to use on your main domain.
1. First, either come up with a subdomain of your main domain to use, or register a completely separate domain name.
1a. If you’re going to use a subdomain, go to your site’s control panel and ensure that it points to the root folder of your main domain.
2. Once your new domain or subdomain is established, go to your site’s control panel and open up the DNS Zone Editor.
3. Create a CNAME record. First, put the domain or subdomain you created in the Name/Label/Alias section of the CNAME record. If you use a subdomain, you need to make sure that your server or application only sets cookies for www.yoursite.com, rather than the top-level version of your site (i.e. yoursite.com).
4. Make sure that your new domain or subdomain points back to your main domain.
5. You MAY also need to select a time-to-live (TTL) value, which says how long your copy will remain in the CDN after it’s copied from your main repository. This is measured in seconds, with 86400 seconds being equivalent to 24 hours. Sometimes your DNS will limit the maximum amount of time you can keep content in your CDN (often about 72 hours). (Hint: If your content changes often, use a shorter TTL, as updated files could take hours to change in a CDN, making it unavailable to users.)
6. Hit “Edit Record” or “OK.”
Now it’s time to serve static content to your new location by modifying the references to your static files to point to your new CDN location. This means that your image locations will change from http://www.yoursite.com/images/image.jpg to your subdomain (e.g. http://cdn.yoursite.com/images/image.jpg) or new domain (e.g. http://www.newdomain.com/images/image.jpg).
You can do this by manually changing the location of each file, but if you’re redirecting a lot of content, that can take a lot of time and effort. Another option is to use a plugin, such as W3 Total Cache, to enable your CDN. To do this:
1. Check the box that says “Enable” (or something like that)
2. Select “Mirror” as your CDN Type from the drop-down menu
3. Go to “Settings” or “CDN Settings”
4. Once in there, set the configuration parameters to replace the site’s main domain with your new domain or subdomain (all other parameters can be left alone)
And there you have it! Understand that some of these steps may have to be altered based on your Web hosting provider or content management system, but this should provide a basic outline for how you can go about setting up your own CDN without shelling out too much money.