Muokkaa

Jaa


Configuring a custom domain name for an Azure cloud service (classic)

Important

Cloud Services (classic) is now deprecated for all customers as of September 1st, 2024. Any existing running deployments will be stopped and shut down by Microsoft and the data will be permanantly lost starting October 2024. New deployments should use the new Azure Resource Manager based deployment model Azure Cloud Services (extended support).

When you create a Cloud Service, Azure assigns it to a subdomain of cloudapp.net. For example, if your Cloud Service is named contoso, your users are able to access your application on a URL like http://contoso.cloudapp.net. Azure also assigns a virtual IP address.

However, you can also expose your application on your own domain name, such as contoso.com. This article explains how to reserve or configure a custom domain name for Cloud Service web roles.

Do you already understand what CNAME and A records are? Jump past the explanation.

Note

The procedures in this task apply to Azure Cloud Services. For App Services, see Map an existing custom DNS name to Azure Web Apps. For storage accounts, see Configure a custom domain name for your Azure Blob storage endpoint.

Tip

Get going faster--use the NEW Azure guided walkthrough! It makes associating a custom domain name AND securing communication (TLS) with Azure Cloud Services or Azure Websites a snap.

Understand CNAME and A records

CNAME (or alias records) and A records both allow you to associate a domain name with a specific server (or service in this case); however, they work differently. There are also some specific considerations when using A records with Azure Cloud services that you should consider before deciding which to use.

CNAME or Alias record

A CNAME record maps a specific domain, such as contoso.com or www.contoso.com, to a canonical domain name. In this case, the canonical domain name is the [myapp].cloudapp.net domain name of your Azure hosted application. Once created, the CNAME creates an alias for the [myapp].cloudapp.net. The CNAME entry resolves to the IP address of your [myapp].cloudapp.net service automatically, so if the IP address of the cloud service changes, you don't have to take any action.

Note

Some domain registrars only allow you to map subdomains when using a CNAME record, such as www.contoso.com, and not root names, such as contoso.com. For more information on CNAME records, see the documentation provided by your registrar, the Wikipedia entry on CNAME record, or the IETF Domain Names - Implementation and Specification document.

A record

An A record maps a domain, such as contoso.com or www.contoso.com, or a wildcard domain such as *.contoso.com, to an IP address. With an Azure Cloud Service, the virtual IP of the service. So the main benefit of an A record over a CNAME record is that you can have one entry that uses a wildcard, such as *.contoso.com, which would handle requests for multiple subdomains such as mail.contoso.com, login.contoso.com, or www.contso.com.

Note

Since an A record is mapped to a static IP address, it cannot automatically resolve changes to the IP address of your Cloud Service. The IP address used by your Cloud Service is allocated the first time you deploy to an empty slot (either production or staging.) If you delete the deployment for the slot, the IP address is released by Azure and any future deployments to the slot may be given a new IP address.

Conveniently, the IP address of a given deployment slot (production or staging) is persisted when swapping between staging and production deployments or performing an in-place upgrade of an existing deployment. For more information on performing these actions, see How to manage cloud services.

Add a CNAME record for your custom domain

To create a CNAME record, you must add a new entry in the DNS table for your custom domain by using the tools provided by your registrar. Each registrar has a similar but slightly different method of specifying a CNAME record, but the concepts are the same.

  1. Use one of these methods to find the .cloudapp.net domain name assigned to your cloud service.

    • Sign into the Azure portal, select your cloud service, look at the Overview section and then find the Site URL entry.

      quick glance section showing the site URL

      OR

    • Install and configure Azure PowerShell, and then use the following command:

      Get-AzureDeployment -ServiceName yourservicename | Select Url
      

      Save the domain name used in the URL returned by either method, as you need it when creating a CNAME record.

  2. Sign into your DNS registrar's website and go to the page for managing DNS. Look for links or areas of the site labeled as Domain Name, DNS, or Name Server Management.

  3. Now find where you can select or enter CNAMEs. You may have to select the record type from a drop-down or go to an advanced settings page. You should look for the words CNAME, Alias, or Subdomains.

  4. You must also provide the domain or subdomain alias for the CNAME, such as www if you want to create an alias for www.customdomain.com. If you want to create an alias for the root domain, it may be listed as the '@' symbol in your registrar's DNS tools.

  5. Then, you must provide a canonical 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 custom domain name of your deployed application:

Alias/Host name/Subdomain Canonical domain
www contoso.cloudapp.net

Note

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 preceding example only applies to traffic at the www subdomain. Since you cannot use wildcards with CNAME records, you must create one CNAME for each domain/subdomain. If you want to direct traffic from subdomains, 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.

Add an A record for your custom domain

To create an A record, you must first find the virtual IP address of your cloud service. Then add a new entry in the DNS table for your custom domain by using the tools provided by your registrar. Each registrar has a similar but slightly different method of specifying an A record, but the concepts are the same.

  1. Use one of the following methods to get the IP address of your cloud service.

    • Sign into the Azure portal, select your cloud service, look at the Overview section and then find the Public IP addresses entry.

      quick glance section showing the VIP

      OR

    • Install and configure Azure PowerShell, and then use the following command:

      get-azurevm -servicename yourservicename | get-azureendpoint -VM {$_.VM} | select Vip
      

      Save the IP address, as you need it when creating an A record.

  2. Sign into your DNS registrar's website and go to the page for managing DNS. Look for links or areas of the site labeled as Domain Name, DNS, or Name Server Management.

  3. Now find where you can select or enter A records. You may have to select the record type from a drop-down, or go to an advanced settings page.

  4. Select or enter the domain or subdomain that uses this A record. For example, select www if you want to create an alias for www.customdomain.com. If you want to create a wildcard entry for all subdomains, enter *****. This entry covers all subdomains such as mail.customdomain.com, login.customdomain.com, and www.customdomain.com.

    If you want to create an A record for the root domain, it may be listed as the '@' symbol in your registrar's DNS tools.

  5. Enter the IP address of your cloud service in the provided field. This step associates the domain entry used in the A record with the IP address of your cloud service deployment.

For example, the following A record forwards all traffic from contoso.com to 137.135.70.239, the IP address of your deployed application:

Host name/Subdomain IP address
@ 137.135.70.239

This example demonstrates creating an A record for the root domain. If you wish to create a wildcard entry to cover all subdomains, you would enter '*****' as the subdomain.

Warning

IP addresses in Azure are dynamic by default. You will probably want to use a reserved IP address to ensure that your IP address does not change.

Next steps