Now, we have to create the backend pool for the application gateway and assign port 80 to it, so that it can be accessed by the application gateway. Take the following steps:
- Create the backend pool and settings, as follows:
$address1 = Get-AzNetworkInterface -ResourceGroupName PacktApplicationGateway -Name PacktNic1
$address2 = Get-AzNetworkInterface -ResourceGroupName PacktApplicationGateway -Name PacktNic2
$backendPool = New-AzApplicationGatewayBackendAddressPool `
-Name PacktGBackendPool `
-BackendIPAddresses $address1.ipconfigurations[0].privateipaddress, $address2.ipconfigurations[0].privateipaddress
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name PacktPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
- Next, we need to create the listener and add a rule. A listener is required to allow the application gateway to route the traffic appropriately to the backend pool. First we need to create a new listener and assign the frontend configuration and frontend port that we created previously to it. Then, we need to create a rule, which is required for the listener to know which backend pool is used for the incoming traffic. Create the listener and add the rule, as follows:
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name PacktAGListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $backendPool `
-BackendHttpSettings $poolSettings