Mapping a custom domain (e.g., yourdomain.com or api.yourdomain.com) to an Azure App Service involves adding domain bindings in Azure, configuring DNS records at your registrar, and binding an SSL/TLS certificate.

Technical Overview & Architecture

User Request ──> https://api.yourdomain.com
                        │
                        ▼ (DNS Registrar - CNAME / A Record)
            your-app.azurewebsites.net
                        │
                        ▼ (Azure App Service Front-End)
             Azure App Service Plan (B1 or higher)

Step 1: Upgrade App Service Plan (If on Free/Shared Tier)

  1. Log in to the Azure Portal.

  2. Search for and select your App Service (e.g., your-app).

  3. In the left navigation menu under App Service Plan, click Scale up (App Service plan).

  4. Select Basic B1 (or higher) and click Apply.

Step 2: Get Domain Binding Parameters in Azure

  1. In your App Service left menu, click Custom domains (under Settings).

  2. Click Add custom domain.

  3. Select your provider type (typically All other domain services).

  4. Enter your custom domain name (e.g., api.yourdomain.com or yourdomain.com).

  5. Choose Domain record type:

    • Use CNAME for subdomains (e.g., api.yourdomain.com).

    • Use A Record for root domains (e.g., yourdomain.com).

  6. Azure will display the required DNS records for validation:

    • Domain validation ID (Custom Domain Verification ID): A TXT record token.

    • Host / CNAME Target: your-app.azurewebsites.net (or the IP address for A Records).

Step 3: Configure DNS Records at Your Registrar

Log in to your DNS registrar (e.g., GoDaddy, Namecheap) and create the validation and routing records.

Option A: Mapping a Subdomain (api.yourdomain.com) via CNAME

Add the following two records to your DNS zone file:

Record TypeHost / NameValue / DestinationTTLDescription
CNAMEapiyour-app.azurewebsites.net600s / 1 HourRoutes traffic to Azure
TXTasuid.apiYOUR_AZURE_CUSTOM_DOMAIN_VERIFICATION_ID600s / 1 HourValidates domain ownership

Option B: Mapping a Root Domain (yourdomain.com) via A Record

Add the following two records to your DNS zone file:

Record TypeHost / NameValue / DestinationTTLDescription
A@YOUR_AZURE_APP_SERVICE_IP600s / 1 HourPoints root domain to IP
TXTasuidYOUR_AZURE_CUSTOM_DOMAIN_VERIFICATION_ID600s / 1 HourValidates domain ownership

Step 4: Validate and Add the Domain in Azure

  1. Return to the custom domains blade in the Azure Portal.

  2. Click Validate. Azure will query public DNS to confirm the TXT and CNAME/A records match.

  3. Once all checkmarks turn green, click Add.

Step 5: Secure with a Managed SSL/TLS Certificate (HTTPS)

Azure App Service provides free managed TLS certificates for custom domains.

  1. On your App Service menu, select Certificates under Settings (or click Add binding next to your domain in the custom domains tab).

  2. Go to the Managed Certificates tab and click Add App Service managed certificate.

  3. Select your custom domain (e.g., api.yourdomain.com).

  4. Click Create.

  5. Once created, go back to Custom domains:

    • Click Add binding next to your domain.

    • TLS/SSL type: SNI SSL

    • Certificate: Select your newly generated managed certificate.

    • Click Add Binding.

  6. Toggle HTTPS Only to On at the top of the Custom domains blade to automatically redirect HTTP traffic to HTTPS.

Step 6: Verification & Testing

Verify that DNS resolution and SSL termination are working:

  1. Verify DNS Resolution:

    Bash

    nslookup api.yourdomain.com
    
  2. Test HTTPS Endpoint:

    Bash

    curl -I https://api.yourdomain.com