Tutorial: Configure a Custom Domain for Azure App Service

This tutorial guides you through the process of mapping your custom domain name (e.g., www.yourdomain.com) to your Azure App Service. This allows users to access your application using a professional and branded URL instead of the default .azurewebsites.net domain.

Prerequisites:
  • An active Azure subscription.
  • An existing Azure App Service.
  • A custom domain name purchased from a domain registrar (e.g., GoDaddy, Namecheap).
  • Access to your domain registrar's DNS management portal.

Why Use Custom Domains?

  • Branding: Reinforce your brand identity with a memorable URL.
  • Professionalism: Present a more credible image to your users.
  • SEO: Potentially improve search engine ranking with a consistent domain.

Steps to Configure a Custom Domain

  1. Navigate to your App Service in the Azure portal. Log in to the Azure portal and select your App Service from the list of resources.
  2. Access Custom Domains settings. In the left-hand menu of your App Service blade, under "Settings," select Custom domains.
  3. Add custom domain. Click the + Add custom domain button.
  4. Enter your domain name. In the "Custom Domain" field, enter your fully qualified domain name (e.g., www.yourdomain.com or blog.yourdomain.com).
  5. Validate. Click the Validate button. Azure will check if you own the domain and if the necessary DNS records are configured. This step requires you to create DNS records at your domain registrar.
  6. Configure DNS Records. You will see instructions on the portal to create two types of DNS records at your domain registrar:
    • A Record: Maps your custom domain to the App Service's external IP address.
    • CNAME Record (for www or subdomains): Maps your custom domain (or subdomain) to your App Service's default hostname (e.g., your-app-name.azurewebsites.net). This is generally preferred for subdomains.
    • TXT Record: Used for domain verification.

    Example DNS Configuration:

    Let's say your domain is yourdomain.com and your App Service is named my-awesome-app.

    For the root domain (yourdomain.com):

    Record Type: A
    Host/Name: @ (or leave blank, depending on registrar)
    Value: [Your App Service IP Address - found in Custom Domains section]
    TTL: 1 Hour
    Record Type: TXT
    Host/Name: @ (or leave blank)
    Value: asuid.yourdomain.com = [Your verification ID - found in Custom Domains section]
    TTL: 1 Hour

    For the www subdomain (www.yourdomain.com):

    Record Type: CNAME
    Host/Name: www
    Value: my-awesome-app.azurewebsites.net
    TTL: 1 Hour
    Record Type: TXT
    Host/Name: asuid.www
    Value: [Your verification ID - found in Custom Domains section]
    TTL: 1 Hour

    Important: The exact values for IP Address, verification ID, and the default hostname can be found in the Azure portal when you attempt to add the custom domain. These values are specific to your App Service instance.

    After updating DNS records at your registrar, it might take some time for these changes to propagate across the internet (typically from a few minutes to 48 hours).

  7. Re-validate and Add. Once DNS propagation is complete, return to the Azure portal and click Validate again. If successful, the "Add custom domain" button will become active. Click it to associate the domain with your App Service.
  8. Binding SSL/TLS Certificate (Recommended). After adding the custom domain, it's crucial to secure it with an SSL/TLS certificate. This enables HTTPS.
    • In the "Custom domains" section, find your newly added domain.
    • Click Add binding.
    • You can either upload your own certificate or use a free App Service Managed Certificate (recommended for simplicity).
    • Select the custom domain, choose your certificate, and select the TLS/SSL Type (SNI SSL is usually sufficient).
    • Click Add Binding.

Troubleshooting

  • DNS Propagation Delay: The most common issue. Allow sufficient time for DNS changes to propagate.
  • Incorrect DNS Records: Double-check the record types, hostnames, and values you entered at your registrar.
  • IP Address Changes: While rare for App Services, if your App Service IP changes, you'll need to update your A record. Using CNAME for subdomains mitigates this.
  • App Service Plan Tier: Custom domains are available on all App Service plan tiers, but SSL binding requires Basic, Standard, Premium, or Isolated tiers.

By following these steps, you can successfully configure a custom domain for your Azure App Service, enhancing your application's accessibility and professional appearance.