How to Configure Custom Domain for Azure App Service
To configure a custom domain for an Azure App Service, first add your domain in the Azure portal under your app's Custom domains section. Then, update your domain's DNS records to point to your app's Azure-provided IP address or CNAME as instructed.
Syntax
Configuring a custom domain involves two main parts:
- Adding the domain in Azure App Service: You specify your custom domain name in the Azure portal.
- Updating DNS records: You create either an A record pointing to the app's IP address or a CNAME record pointing to the app's default domain.
bash
az webapp config hostname add --resource-group <resource-group-name> --name <app-service-name> --hostname <custom-domain>
Example
This example shows how to add a custom domain www.example.com to an Azure App Service named myappservice in resource group myResourceGroup. It also explains how to update DNS records.
bash
az webapp config hostname add --resource-group myResourceGroup --name myappservice --hostname www.example.com
Output
Hostname www.example.com added to webapp myappservice
Common Pitfalls
- Not verifying domain ownership: Azure requires you to prove you own the domain by adding a TXT record or using the provided IP/CNAME.
- Incorrect DNS records: Using wrong IP address or forgetting to add CNAME can cause the domain not to resolve.
- SSL certificate missing: Custom domains need SSL certificates for secure HTTPS access.
bash
## Wrong DNS example (missing CNAME) # DNS record missing or incorrect ## Correct DNS example # Add CNAME record: # Host: www # Points to: myappservice.azurewebsites.net
Quick Reference
| Step | Action | Details |
|---|---|---|
| 1 | Add custom domain in Azure | Use Azure portal or CLI to add your domain to the app service |
| 2 | Verify domain ownership | Add TXT record or use IP/CNAME verification as instructed |
| 3 | Update DNS records | Create A or CNAME record pointing to your app service |
| 4 | Enable SSL | Bind SSL certificate to your custom domain for HTTPS |
Key Takeaways
Add your custom domain in Azure App Service before updating DNS records.
Verify domain ownership by adding required DNS TXT or CNAME records.
Use correct DNS records: A record for IP or CNAME for Azure domain.
Enable SSL certificates to secure your custom domain with HTTPS.
Check DNS propagation to confirm your domain points correctly to the app.