Sat, 14 Mar 2009

Custom Domain Names in Windows Azure

Fairly often I get asked how I have my own custom domain (http://blog.smarx.com) pointing to my blog application running in Windows Azure.  Recently I launched a new service called Botomatic, for which I also use a custom domain (http://www.botomatic.com), so the question is coming up again.  I thought I’d take a few minutes to show you how I set up the botomatic.com domain for use with Windows Azure.

The Theory

Windows Azure provides a friendly DNS name like “blogsmarx.cloudapp.net” or “botomatic.cloudapp.net.”  There’s a reason for providing these (other than simply being prettier than an IP address).  These are a necessary abstraction layer that lets the Virtual IP addresses (VIPs) underneath change without disrupting your service.  It’s rare for the VIP of an application to change, but particularly thinking ahead to geo-location scenarios, it’s important that Windows Azure reserves the right to change the VIP.  The friendly DNS entries provide a consistent interface for users to get to your application.

In general, you have two options for setting up a domain name to point to a location.  The first is to use an A record to point to a specific IP address, but as we just discussed, this isn’t an option in Windows Azure where the IP address may change.  The second method is to use a CNAME record, which can map a specific subdomain to another (named) DNS entry.  This is what you need to do to map your domain to a Windows Azure application.

Step-by-Step Guide

I used GoDaddy as my registrar for Botomatic, but other registrars presumably have similar mechanisms.  There are just two simple steps to getting this working.

Add the CNAME record

Step one is to create a CNAME record mapping the “www” subdomain (as in www.botomatic.com) to my Windows Azure application (botomatic.cloudapp.net).  Here’s what that looks like using GoDaddy:

image

Forward the root domain

Step two is to use domain forwarding to map the root domain (botomatic.com) to the subdomain we already mapped (www.botomatic.com).  Here’s what that looks like using GoDaddy: image

Gotchas

CNAME records have one limitation: they need to map a specific subdomain.  In the above example, we used “www.”  For my blog, I used “blog.”  It’s not possible with a CNAME record to map the root domain itself, which is why we needed to forward as above.  It’s also not possible with a CNAME record to do wildcard mappings (like “*.botomatic.com”).