azureazure-web-app-serviceazure-dns

Azure Web App - Change Exisitng Web App to use a New Custom Domain


I support an existing Azure web-app that is linked to a custom domain. App Service Certificates are used to for the Web Apps TLS settings and bind to the custom domain.

There is now a requirement to register a new custom domain (using Azure is OK), un-link the exsiting domain and config-link the new custom domain to the existing Azure web-app.

I am trying to figure out a logical ordering of steps to achieve this. The Azure web-app is live however over the weekend the web-app is not in use. There are 3 non-production environments to test out the sequence of steps to ensure the web-site still remains accessible after the change.

Can you help with the sequence of steps to achieve the above?

Regards


Solution

  • There are 2 ways to add a new custom domain in the Azure Web Application:

    1. Removing the existing custom domain and configuring the new Custom Domain Name
    2. Using Deployment Slots

    Way 1: A) Remove the existing Custom Domain:

    If your hostname has SSL bindings, remove them first and then delete the hostname.

    Using PowerShell: If the web application having multiple custom domain names/

    $webApp = Get-AzWebApp -ResourceGroupName "<<Resource-Group-Name>>" -Name "<<App_Name>>"
    $webApp.HostNames.Clear()
    $webApp.Hostnames.Add($webApp.DefaultHostName)
    set-AzWebApp -ResourceGroupName "<<Resource-Group-Name>>" -Name 
    <<App_Name>> -HostNames $webApp.HostNames
    

    The above cmdlets will remove the all custom hostnames except the default one.

    To remove a specific hostname for the collection:

    $webApp.HostNames.Remove("your_hostname_goes_here")
    

    To know the limitations in deleting a custom domain name, please refer this MS Doc.

    B) Adding a New Custom Domain:

    1. Before Adding the Custom Domain, make sure you edit DNS records to add DNS entries for the root domain.
    2. To get a domain verification Id, go to Azure Portal > <Your App Service> > Custom domains - Copy CDV ID and IP address.
    3. Create the DNS Records for your domain and enable the mapping in your app. For more information, please refer this MS Doc and article.

    The above documentation also contains the information of securing the custom DNS with a TLS/SSL binding and migration of domain from one to another App.

    Way 2: Using Deployment Slots

    az webapp config hostname add [--hostname]
                              [--ids]
                              [--resource-group]
                              [--slot]
                              [--subscription]
                              [--webapp-name]
    

    For more information, you can refer this MS Doc of Set up Deployment Slot Environments in Azure App Service and an Stackify article of azure deployment slots.