Microsoft Azure MVP

Script: Assign a custom domain to an Azure web app

Andrew Gravell
Rate this post

The following script sample demonstrates how to configure a custom domain on an Azure web app using Azure CLI 2.0.  If you want to do it manually, please refer to this Azure document.

The script code does the following:

  1. Create a web app in Azure App Service in the West Europe Azure region.
  2. Upgrade the App Service plan to SHARED tier (minimum required by custom domains).
  3. Configure the custom domain on the web app.

To run the script, you need to run az login to log into Azure, and make sure you have already added a CNAME record or an A record in your DNS provider to point to <yourappname>.azurewebsites.net

#!/bin/bash

#### This script currently DOES NOT WORK. PU is working on fixing an error message ####

           
            

$fqdn=<Replace with your custom domain name>> webappname=mywebapp$RANDOM # Create a resource group. az group create --location westeurope --name $webappname # Create an App Service plan in FREE tier. az appservice plan create --name $webappname --resource-group $webappname --sku FREE # Create a web app. az appservice web create --name $webappname --resource-group $webappname --plan $webappname # Upgrade App Service plan to SHARED tier (minimum required by custom domains) az appservice plan update --name $webappname --resource-group $webappname --sku SHARED # Add a custom domain name to the web app. az appservice web config hostname add -webapp $webappname --resource-group $webappname --name $fqdn


Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...
1Code.Blog - Your #1 Code Blog