Configuring a custom domain name for a Windows Azure cloud service
When you create an application in Windows Azure, Windows Azure provides a friendly subdomain on the cloudapp.net domain so your users can access your application on a URL like http://<myapp>.cloudapp.net. However, you can also expose your application on your own domain name, such as contoso.com.
This task will show you how to:
Expose your application on a custom domain
There are two ways you can configure the Domain Name Server (DNS) settings on your domain registrar to point to your Windows Azure hosted service:
CNAME or Alias record (preferred)
With a CNAME, you map a specific domain, such as www.contoso.com or myblog.contoso.com, to the <myapp>.cloudapp.net domain name of your Windows Azure hosted application. The lifetime of the <myapp>.cloudapp.net domain name required to implement this solution is the lifetime of your hosted service and persists even if your hosted service does not contain any deployments.
Note, however, that most domain registrars only allow you to map subdomains, such as www.contoso.com and not root names, such as contoso.com, or wildcard names, such as *.contoso.com.
With an A record, you map a domain (e.g., contoso.com or www.contoso.com) or a wildcard domain (e.g., *.contoso.com) to the single public IP address of a deployment within a Windows Azure hosted service. Accordingly, the lifetime of this IP address is the lifetime of a deployment within your hosted service. The IP address gets created the first time you deploy to an empty slot (either production or staging) in the hosted service and is retained by the slot until you delete the deployment from that slot. You can discover this IP address from within the Windows Azure Management Portal.
The main benefit of this approach over using CNAMEs is that you can map root domains (e.g., contoso.com) and wildcard domains (e.g., *.contoso.com), in addition to subdomains (e.g., www.contoso.com).
Note, however, because the lifetime of the IP address is associated with a deployment, it is important not to delete your deployment if you need the IP address to persist. Conveniently, the IP address of a given deployment slot (production or staging) is persisted when using the two upgrade mechanisms in Windows Azure: VIP swaps and in-place upgrades.
The remainder of this section focuses on the CNAME approach.
Add a CNAME record for your custom domain
To configure a custom domain name, you must create a new CNAME record in your custom domain name's DNS table. Each registrar has a similar but slightly different method of specifying a CNAME record, but the concept is the same.
Log on to your DNS registrar's web site, and go to the page for managing DNS. You might find this in a section, such as Domain Name, DNS, or Name Server Management.
Now find the section for managing CNAME's. You may have to go to an advanced settings page and look for the words CNAME, Alias, or Subdomains.
Finally, you must provide a subdomain alias, such as www. Then, you must provide a host name, which is your application's cloudapp.net domain in this case. For example, the following CNAME record forwards all traffic from www.contoso.com to contoso.cloudapp.net, the DNS name of our deployed application:
|Alias ||Host name |
|www ||contoso.cloudapp.net |
A visitor of www.contoso.com will never see the true host (contoso.cloudapp.net), so the forwarding process is invisible to the end user.
The example above only applies to traffic at the www subdomain. You cannot specify a root CNAME record that directs all traffic from a custom domain to your cloudapp.net address, so additional alias records must be added. If you want to direct all traffic from a root domain, such as contoso.com, to your cloudapp.net address, you can configure a URL Redirect or URL Forward entry in your DNS settings, or create an A record as described earlier.