Post

How to Setup a Custom Domain on App Service

Azure App Service allows you to connect your custom domain to an web application you have deployed on App Service.

In this tutorial, we will go through the steps on how to connect a domain name managed through Cloudflare as a custom domain to point to a Web App that you have deployed on App Service.

This content is available in video form on the Cloud Engineer Skills YouTube channel.

Setup a Custom Domain on an App Service Web App using Azure CLI

Before we can map a custom domain to an App Service Web App, first we will need to creating the following resources in Azure.

  • Resource Group
  • App Service Plan
  • Web App

Setup Resource Plan, App Service Plan and Web App

We will go over the process of creating these resources quickly in this post, for more detail on how to do this, check out the post How to Deploy an App Service Web App using Azure CLI.

We will start by setting up logging into your Azure account and subscription using the Azure CLI, and then creating a resource group.

1
2
az login
az group create --name cloudengineerskills-domain-rg --location eastus

Next, we will create the App Service Plan, one thing to note is Custom Domains are only supported on paid App Service Plan pricing tiers and not the Free (F1) tier.

1
az appservice plan create --resource-group cloudengineerskills-domain-rg --name NodeAppPlan --number-of-workers 1 --sku B1 --is-linux

Now, we will create the Web App that in this example will be a running instance of the nginx container image from Docker Hub.

1
az webapp create -n CloudEngineerSkillsContainer -g cloudengineerskills-domain-rg -p NodeAppPlan -i nginx

Verify the Web App is running nginx on the host name provided by App Service by querying the default host name using the following commmand, and copying the host name into a web browser.

1
az webapp list --resource-group cloudengineerskills-domain-rg --query "[].{name: name, hostName: defaultHostName, state: state}"

Setup App Service Custom Domain in the Azure Portal

Next, we will need to login to the Azure Portal, and select the App Service that we have created.

In the left hand sidebar, open the Settings option and select Custom Domains.

Select the Add custom domain option.

In this example I will be using Cloudflare as my domain provider and I will be pointing the domain sweskills.com to the Web App deployed on App Service.

For the Domain provider select All other domain services.

For the TLS/SSL certificate select App Service Managed Certificate.

For the TLS/SSL type select SNI SLL.

Under Domain enter your domain, in my case it will be sweskills.com.

If you are not using a subdomain, set the Hostname record type to an A record (example.com).

If you are using a subdomain, set the Hostname record type to CNAME (www.example.com or any subdomain).

Next you will need to copy the A or CNAME record and the TXT record and add them as DNS entries into your domain provider, in my case it is Cloudflare.

Update DNS Records into Cloudflare

Now we will update DNS records that we have received in the Azure Portal in the previous step into our domain provider in this case Cloudflare.

In Cloudflare, log into the Cloudflare dashboard, then select Websites in the left side bar.

From there, select your website’s domain you wish to use.

In the side bar on the left, select DNS, then select Records, then under the DNS management section we will add new records for the A or CNAME record and the TXT record.

To do this, select Add record, then enter the values from the Azure Portal for the A or CNAME record and the TXT record.

For the A and CNAME record you will need to turn Proxy status off in Cloudflare.

Give it some time to propagate the changes to the DNS records to DNS name servers. I’ve seen this work after 5 minutes, most of the time it’s done within 2 hours, occassionaly it may take longer.

Once this is complete, go back to the Azure Portal and select Validate.

If the validation check fails, recheck you have entered the DNS records correctly and it give it some more time for the DNS records to propagate before you run the validation check again.

Automated SSL Certificate Setup with App Service Managed Certificate

If the validation check passes, select Add, you will then need to wait for Adding custom domain and SSL binding to complete.

This step is automating the creation and installation of a free App Service managed certificate provided by Azure. They will also take care of automated certificate renewals at 6 monthly increments for you.

Once it is has completed successfully, enter your custom domain into a web browser and you should be directed your App Service Web App.

Clean up the resources

Delete your Resource Group with the az group delete command, which will clean up the App Service Plan, and App Service resources aswell.

1
az group delete --name cloudengineerskills-domain-rg

Further Reading

This post is licensed under CC BY 4.0 by the author.