Azure – Networking – Part 7 – Create An Application Gateway With URL-Based Routing Configuration- 1
Hello Everybody,
I hope, you all are doing good. Today let’s continue with Azure Application Gateway in this articles. In this article we will create and configure one Azure Application Gateway to support URL-Based Routing. In our last blog, we have discussed about URL-Based Routing as a feature of AG .
Tool Installation Articles :
- Configure Azure Command Line Interface ( Azure CLI) On Windows
- Configure PowerShell For Microsoft Azure Az Module On Windows
Previous Azure series :
- Learn Basics Of Azure Networking In 60 Hours
- Learn Basic Of Azure Active Directory And Azure Identity And Access Management
- Azure DevOps – Learn at one place
If you have missed our previous articles on networking, please check them in following links.
Part 1 – Basics of Azure Networking
Part 2 – Azure Virtual Network (VNet)
Part 3 – Subnet in Azure Network
Part 4 – Network Security Group (NSG) in Azure
Part 5 – Basics of Azure Application Gateway
Part 6 – Azure Application Gateway Features
Next Article : Part 8 – PowerShell To Create An Application Gateway With URL-Based Routing Configuration- 2
Here I am using Azure Cloud Shell for our exercise. Azure hosts Azure Cloud Shell, an interactive shell environment that we can use through our browser. We don’t have to install anything on our local environment.
Select the Cloud Shell button on the top-right menu bar in the Azure portal as shown in the following figure.

A. Resource Group and Virtual Network :
To proceed with the application gateway, the first step is to be ready with our Resource Group and Virtual network.
We can create if we don’t have it already. In our case, We have already created them. So here we can use them.
Let’s collect all those resources, we need to create our Application Gateway. Note: In this example, I used “KJ” as prefix with the name for all resource I am creating. So that I can recognize my resources.
1) Get the exiting VNet by using Get-AzVirtualNetwork by providing the name of VNet and Resource Group as shown in the following image.

2) Get Subnet, which we created for application gateway as shown in the following figure. In my case the first subnet of the collection “AG_Subnet” is for application gateway.

3) Let’s Create one public IP using New-AzPublicIpAddress. This Public IP will be used to provide network connectivity to the application gateway and it’s associated resources.

If we already have one public IP for this purpose, we can get that one using Get-AzPublicIpAddress command as shown in the following figure.

B. Create an application gateway:
Before we create Application Gateway, we need following supporting resource in advance.
1) Application Gateway IP Configuration : It associates our subnet to the application gateway. This IP configuration contains the subnet in which application gateway is deployed. We will use New-AzApplicationGatewayIPConfiguration command to create IP config.

2) Application Gateway Front-end IP Configuration : It associate our public IP to the application gateway. We can create this IP config using New-AzApplicationGatewayFrontendIPConfig command.

3) Front-end Port : Assigns a port to use by the default listener to access app. Use New-AzApplicationGatewayFrontendPort command to create this port.

4) Default BackEnd pool : All application gateways must have at least one backend pool of servers. We can use New-AzApplicationGatewayBackendAddressPool command to create new backend pool as shown in the following figure.
5) Default HttpSetting : Configure the HttpSettings for the backend pool using New-AzApplicationGatewayBackendHttpSettings.

6) Default Listener : The default listener listens for traffic on the port that was assigned. New-AzApplicationGatewayHttpListener command needs to use to create new listener.
7) Default Rule : The default rule is used to sends traffics to the default backend pool. We will use New-AzApplicationGatewayRequestRoutingRule command to create new rule.
8) Stock Keeping Unit (SKU) : The New-AzApplicationGatewaySku cmdlet creates a stock keeping unit (SKU) for an Azure application gateway.
9) Application Gateway : The cmdlet New-AzApplicationGateway is used to create and configure a Azure Application Gateway. Following figure sowing , how to use all of the above commands and passing those resource to New-AzApplicationGateway cmdlet to create application gateway.

Our application gateway is ready with all default configuration. Now we will configure our application gateway for our requirement, to redirect traffic to correct backend pool based on Url of the request. To achieve that , let’s continue with below steps.
Note : When working with Azure Cloud Shell, if we be idle for 20 minute then it will ask for reconnect and it clear all local variable. In that case we need to get all required resource again before utilized them.
C. Configure New Image And Video Backend Pools :
1) Get Application Gateway : Get existing application gateway using Get-AzApplicationGateway command by passing resource name and application gateway name.
2) Add New Backend Pool : Add two backend pool, one is to serve Image request and other one is for Video request. Add-AzApplicationGatewayBackendAddressPool is used to add new backend pool to application gateway as shown in the following image.

Now let’s add one more back end pool for video as shown in the following figure.

3) Add New FrontEnd Port : Add-AzApplicationGatewayFrontendPort command add a new front end port for the application gateway . We will use this port, when add a new Http Setting.

4) Set Application Gateway: To save all changes to application gateway, set the application gateway frequently by using Set-AzApplicationGateway cmdlet. This command updates the application gateway with settings in the $AppGw variable as show in the following figure.

D. Add New Listener :
1) Get Application Gateway : Before add a new listener, get the correct application gateway by providing the name as we have done in previous section.
2) Get Front-end Port : Get existing front end port using Get-AzApplicationGatewayFrontendPort as shown in the following figure.

3) Get front-end IP config : Get exiting front end IP config of application gateway by using Get-AzApplicationGatewayFrontendIPConfig .
4) Add New Listener and Set Application Gateway: Add a new listener to listen our Url based traffic by using Add-AzApplicationGatewayHttpListener as shown in the following figure.

E. Add Url Path Map Config :
1) Get Application Gateway: Get existing application gateway using Get-AzApplicationGateway command .
2) Get Httpsetting : Get existing Httpsetting by using Get-AzApplicationGatewayBackendHttpSettings cmdlet.
3) Get Backend Pools : Get all existing backend pools, created in previous steps using Get-AzApplicationGatewayBackendAddressPool command as shown in the following figure.

4) Add URL Path Map Config And Set AG : Using Add-AzApplicationGatewayUrlPathMapConfig cmdlet adds an array of URL path mappings to a back end server pool.

F. Add Routing Rule:
1) Get Application Gateway: Get existing application gateway using Get-AzApplicationGateway command .
2) Get Listener : We have created a new listener (“KJ_BackendListener”) for our requirement in above steps. Let’s get the listener by using Get-AzApplicationGatewayHttpListener cmdlet.
3) Get Url Path Mapping Config : Get the existing Url path map configuration by using Get-AzApplicationGatewayUrlPathMapConfig cmdlet.
4) Add New Path Based Routing Rule : The Add-AzApplicationGatewayRequestRoutingRule cmdlet adds a request routing rule to an application gateway as shown in the following figure.

5) Set Application Gateway: To save all changes to application gateway, set the application gateway frequently by using Set-AzApplicationGateway cmdlet.
G. Create Virtual Machine Scale Sets ( VMSS) :
Azure virtual machine scale sets let you create and manage a group of identical, load balanced VMs. The number of VM instances can automatically increase or decrease in response to demand or a defined schedule (From MS doc).
Here we will create 3 different VMSS for our 3 different backend pool. So that when different traffic redirect to different backend pool based on its Url. There will be one VMSS to address the request. we need following resources and information to create one VMSS.
- Get Existing VNet by using Get-AzVirtualNetwork cmdlet.
- Get Application Gateway using Get-AzApplicationGateway cmdlet .
- Get First Backend Pool using Get-AzApplicationGatewayBackendAddressPool cmdlet by providing backend pool name.
- Create New IP Config For VMSS of the current Backend Pool using New-AzVmssIpConfig cmdlet.
- The New-AzVmssConfig cmdlet creates a configurable local Virtual Manager Scale Set (VMSS) object.
- Set Storage Profile properties For VM Scale Set using Set-AzVmssStorageProfile cmdlet.
- Sets the VMSS operating system profile properties using Set-AzVmssOsProfile cmdlet.
- Adds a network interface configuration to the VMSS using Add-AzVmssNetworkInterfaceConfiguration cmdlet.
- Create new VMSS for the current backend pool using New-AzVmss cmdlet.
- Do the steps from 3 to 9 for rest of two backend pool.

H) Install IIS To All VMSS :
Once we have created VMSS for all backend pool, let’s install IIS to all VMSS using a script provided by microsoft in the following link.
“https://raw.githubusercontent.com/Azure/azure-docs-powershell-samples/master/application-gateway/iis/appgatewayurl.ps1”.
- Create a publicSetting for the above link.
- Get one VMSS object using Get-AzVmss cmdlet by providing the name of the VMSS.
- Adds an extension to the VMSS using Add-AzVmssExtension cmdlet by providing publishSetting we created earlier.
- Update the VMSS using Update-AzVmss cmdlet.
- Do all steps from 2 to 4 for rest of the VMSS.


I) Test The Application Gateway :
Now we are all set to test our AG. For that let’s get hte public Ip of the application gateway using the following cmdlet.
Get-AzPublicIPAddress -ResourceGroupName *_RG -Name ourPublicIPName
Once we got our IP then test the following links by replace ***.**.*.* with our public IP.
http:// ***.**.*.*
http:// ***.**.*.* :8080/video/test.htm
http:// ***.**.*.* :8080/images/test.htm

I hope this article gives an idea to configure Application Gateway . In my next post, we we can download complete script to configure the Application Gateway. My next article of this series is Part 8 – PowerShell To Create An Application Gateway With URL-Based Routing Configuration- 2 .
Thanks for reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.
5 Responses
[…] I will continue with our last article Create An Application Gateway With URL-Based Routing Configuration- 1 . As I said in last article, in this article I would only go through the power shell used in my […]
[…] Next Article : Part 7 – Create An Application Gateway With URL-Based Routing Configuration- 1 […]
[…] Part 7 – Create An Application Gateway With URL-Based Routing Configuration- 1 […]
[…] Chapter 7 – Create An Application Gateway With URL-Based Routing Configuration- 1 […]
[…] Part 7 – Create An Application Gateway With URL-Based Routing Configuration- 1 […]
You must log in to post a comment.