The Azure CDN (Content Delivery Network) service is a pretty awesome feature which enables you to serve your website content to an end-user from the closest geographical server to them, decreasing load times and cutting down on general internet traffic (which can only be a good thing)!
You can create a new CDN service in just a few clicks through the Azure Management Portal, and you can choose your content source to be Azure Blob Storage, a Cloud Service, a Web App or a custom source.
One great feature I’ve discovered with the Azure CDN service recently is the ability to use a custom domain name! So if I wanted to serve all my blog images through Azure’s CDN service using a custom domain such as content.maffrigby.com I can do that!
First you have to set up your domain name in your DNS server. So set up a sub-domain such as content.maffrigby.com and create a CNAME record, pointing to the Azure CDN end point you just set up. This will be something like az783031.vo.msecnd.net and should look a bit like this when set up:
Once you have set up your domain name record, go back to your CDN service in the Azure Portal and click on the “Manage Domains” icon at the bottom of the screen. You will see a screen that looks like this:
Simply add in your custom domain name and Azure will attempt to verify it by ensuring the CNAME record is indeed pointing to the CDN endpoint Url. If everything is good, you should see a green tick next to your domain name. If you don’t see the green tick, then you’ve done something wrong with your domain name setup. Go sort that out and try again.
Once you click the ‘OK’ tick on this screen, Azure will do what it needs to do in order to set up that custom domain name on your CDN service.
The only other thing you need to do is have a bit of patience – it can take a while for these changes to kick in, and you might get 404 errors when you’re trying to access your CDN-ed content through your custom domain name. Go have a cup of tea, or two cups of tea and then try again.