Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/app-service/custom-domains.md
1# App Service Custom Domains and Managed TLS23## Prerequisites45| Requirement | Details |6|------------|---------|7| SKU tier | Basic (B1) or higher |8| DNS access | Ability to create CNAME, A, and TXT records |9| Domain ownership | Verified via TXT record |1011## DNS Configuration1213### Subdomain (CNAME)1415| Record Type | Name | Value |16|------------|------|-------|17| CNAME | `www` | `<app-name>.azurewebsites.net` |18| TXT | `asuid.www` | `<verification-id>` |1920### Apex / Root Domain (A Record)2122| Record Type | Name | Value |23|------------|------|-------|24| A | `@` | `<app-ip-address>` |25| TXT | `asuid` | `<verification-id>` |2627Get the verification ID and IP address:2829```bash30# Get verification ID31az webapp show -n $APP -g $RG --query "customDomainVerificationId" -o tsv3233# Get IP address (for A records)34az webapp show -n $APP -g $RG --query "inboundIpAddress" -o tsv35```3637> 💡 **Tip:** Prefer CNAME records for subdomains. For apex domains, consider using an Azure DNS alias record to avoid hardcoding IP addresses that may change.3839## Bind Custom Domain via CLI4041```bash42# Add custom domain43az webapp config hostname add -n $APP -g $RG --hostname www.contoso.com4445# Create managed certificate (free)46az webapp config ssl create -n $APP -g $RG --hostname www.contoso.com4748# Capture certificate thumbprint49THUMBPRINT=$(az webapp config ssl list -n $APP -g $RG \50--query "[?contains(hostNames, 'www.contoso.com')].thumbprint | [0]" -o tsv)5152# Bind the certificate53az webapp config ssl bind -n $APP -g $RG \54--certificate-thumbprint $THUMBPRINT --ssl-type SNI55```5657## Bicep — Custom Domain with Managed Certificate5859```bicep60resource customDomain 'Microsoft.Web/sites/hostNameBindings@2022-09-01' = {61parent: webApp62name: 'www.contoso.com'63properties: {64siteName: webApp.name65hostNameType: 'Verified'66sslState: 'Disabled' // enable after cert is created67}68}6970resource managedCert 'Microsoft.Web/certificates@2022-09-01' = {71name: 'www.contoso.com'72location: location73properties: {74serverFarmId: appServicePlan.id75canonicalName: 'www.contoso.com'76}77dependsOn: [customDomain]78}79```8081Then run a follow-up Bicep deployment to enable SNI and bind the managed certificate to the hostname:8283```bicep84resource managedCert 'Microsoft.Web/certificates@2022-09-01' existing = {85name: 'www.contoso.com'86}8788resource customDomainTlsBinding 'Microsoft.Web/sites/hostNameBindings@2022-09-01' = {89parent: webApp90name: 'www.contoso.com'91properties: {92siteName: webApp.name93hostNameType: 'Verified'94sslState: 'SniEnabled'95thumbprint: managedCert.properties.thumbprint96}97}98```99100> ⚠️ **Warning:** Managed certificate creation requires the DNS records to be in place first. The hostname binding must exist before requesting the certificate.101102## Terraform — Custom Domain with Managed Certificate103104```hcl105resource "azurerm_app_service_custom_hostname_binding" "domain" {106hostname = "www.contoso.com"107app_service_name = azurerm_linux_web_app.app.name108resource_group_name = azurerm_resource_group.rg.name109}110111resource "azurerm_app_service_managed_certificate" "cert" {112custom_hostname_binding_id = azurerm_app_service_custom_hostname_binding.domain.id113}114115resource "azurerm_app_service_certificate_binding" "binding" {116hostname_binding_id = azurerm_app_service_custom_hostname_binding.domain.id117certificate_id = azurerm_app_service_managed_certificate.cert.id118ssl_state = "SniEnabled"119}120```121122## TLS Options123124| Option | Cost | Renewal | Use Case |125|--------|------|---------|----------|126| App Service Managed Certificate | Free | Auto-renewed | Standard custom domains |127| App Service Certificate (purchased) | ~$70/yr | Auto-renewed | Extended validation, wildcard |128| Bring your own certificate | Varies | Manual | Enterprise PKI, specific CA |129130### Enforce HTTPS Only131132```bicep133resource webApp 'Microsoft.Web/sites@2022-09-01' = {134name: appName135location: location136properties: {137httpsOnly: true138// ...139}140}141```142143```hcl144resource "azurerm_linux_web_app" "app" {145name = var.app_name146# ...147https_only = true148}149```150151## Minimum TLS Version152153```bash154# Set minimum TLS version to 1.2155az webapp config set -n $APP -g $RG --min-tls-version 1.2156```157158```bicep159siteConfig: {160minTlsVersion: '1.2'161}162```163164> ⚠️ **Warning:** TLS 1.0 and 1.1 are deprecated. Always set minimum TLS version to 1.2 for production workloads.165166## Troubleshooting167168| Issue | Cause | Fix |169|-------|-------|-----|170| Domain verification fails | Missing TXT record | Add `asuid` TXT record and wait for DNS propagation |171| Certificate creation fails | DNS not yet propagated | Wait 5-15 min for propagation; verify with `nslookup` |172| SSL binding error | SKU too low | Upgrade to Basic (B1) or higher |173| Managed cert not renewing | DNS record changed | Verify CNAME/A record still points to the app |174