Add a custom domain and a free TLS certificate
In this task you'll add a custom domain and TLS certificate to a web app.
A custom domain lets people reach your app at your own address, such as shop.sskaiser.example, instead of an azurewebsites.net address. You prove you own the domain by adding DNS records at whoever manages it.
To make HTTPS work on that address you need a TLS certificate. App Service can create and renew a free managed certificate for you on Basic tier and above.
Example. SS Kaiser points shop.sskaiser.example at its web app with a CNAME record, adds the verification TXT record, then creates a free managed certificate so customers see the padlock.
Costs money. Custom domains need the Basic tier or higher. A Basic B1 plan costs about 0.018 USD an hour (roughly 1.5p, or £10 a month) while it exists. You also need a domain name you own. If you don't have one, follow along by reading the screens on the Free tier.
Before you start
You need: Contributor on the app, and access to your domain's DNS records. Time: 20 minutes.
Where to look
- App Services
- app-practice
- Settings
- Custom domains
Steps
- Open the app and select Custom domains. On the Free tier you'll see that custom domains need a higher tier. To follow along without paying, stop here and read the rest.
- To try it for real, select Scale up (under App Service plan) and move the plan to Basic B1.From this moment the plan costs money every hour until you scale back down or delete it.
- Back in Custom domains, select + Add custom domain. Choose App Service Managed Certificate for TLS and type your domain, such as www plus your own domain.
- The form shows two records to add at your DNS provider: a CNAME and a TXT record. Add them, wait a few minutes, then select Validate.
- When both records show green ticks, select Add. The certificate is created and bound, which can take a few minutes.The free certificate lasts six months and App Service renews it for you. DNS changes usually show up within minutes, but a resolver that looked up the name before you added it can keep saying it doesn't exist for up to an hour.
- Open https:// plus your domain and check the padlock. Then scale the plan back to Free F1 if you're not keeping it.Remove the custom domain first, because Free can't keep it.
Commands
# Move the plan to Basic (costs money from now)
az appservice plan update --resource-group rg-portal-practice --name asp-practice --sku B1
# Add the hostname (after creating the CNAME and TXT records)
az webapp config hostname add --resource-group rg-portal-practice --webapp-name <app name> --hostname www.yourdomain
# Create a free managed certificate and bind it
az webapp config ssl create --resource-group rg-portal-practice --name <app name> --hostname www.yourdomain
# Back to Free when you've finished (remove the hostname first)
az appservice plan update --resource-group rg-portal-practice --name asp-practice --sku F1
Watch out for
- Cost
- Basic and above cost money every hour the plan exists. Managed certificates are free; certificates bought through App Service are not.
- Security
- Only add domains you own. When you delete an app, also remove its DNS records, or someone could take over the dangling name.
- Common mistakes
- Adding the CNAME but not the TXT record, so validation fails. DNS changes taking time to spread: wait and validate again. Trying to scale back to Free while a custom domain is still bound.
Clean up
- app-practice
- Custom domains
Delete the custom domain binding and the certificate, scale the plan back to Free F1 (or delete the resource group), and remove the CNAME and TXT records at your DNS provider.
Words to know
- CNAME record
- A DNS record that says one name is an alias for another, such as shop pointing to the azurewebsites.net address.
- TXT verification record
- A DNS record (named asuid...) that proves to Azure you control the domain.
- Managed certificate
- A free TLS certificate that App Service creates and renews for you.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On