Azure Application Gateway
Azure Application Gateway
Azure Application Gateway is a web traffic load balancer that enables you to manage traffic to your web
applications. Traditional load balancers operate at the transport layer (OSI layer 4 - TCP and UDP) and route
traffic based on source IP address and port, to a destination IP address and port.
Application Gateway can make routing decisions based on additional attributes of an HTTP request, for example
URI path or host headers. For example, you can route traffic based on the incoming URL. So if /images is in the
incoming URL, you can route traffic to a specific set of servers (known as a pool) configured for images. If
/video is in the URL, that traffic is routed to another pool that's optimized for videos.
This type of routing is known as application layer (OSI layer 7) load balancing. Azure Application Gateway can
do URL-based routing and more.
NOTE
Azure provides a suite of fully managed load-balancing solutions for your scenarios.
If you are looking to do DNS based global routing and do not have requirements for Transport Layer Security (TLS)
protocol termination ("SSL offload"), per-HTTP/HTTPS request or application-layer processing, review Traffic Manager.
If you need to optimize global routing of your web traffic and optimize top-tier end-user performance and reliability
through quick global failover, see Front Door.
To do network layer load balancing, review Load Balancer.
Your end-to-end scenarios may benefit from combining these solutions as needed. For an Azure load-balancing options
comparison, see Overview of load-balancing options in Azure.
Features
To learn about Application Gateway features, see Azure Application Gateway features.
Pricing and SLA
For Application Gateway pricing information, see Application Gateway pricing.
For Application Gateway SLA information, see Application Gateway SLA.
What's new
To learn what's new with Azure Application Gateway, see Azure updates.
Next steps
Depending on your requirements and environment, you can create a test Application Gateway using either the
Azure portal, Azure PowerShell, or Azure CLI.
Quickstart: Direct web traffic with Azure Application Gateway - Azure portal
Quickstart: Direct web traffic with Azure Application Gateway - Azure PowerShell
Quickstart: Direct web traffic with Azure Application Gateway - Azure CLI
Quickstart: Direct web traffic with Azure Application
Gateway - Azure portal
3/5/2021 • 9 minutes to read • Edit Online
In this quickstart, you use the Azure portal to create an application gateway. Then you test it to make sure it
works correctly.
The application gateway directs application web traffic to specific resources in a backend pool. You assign
listeners to ports, create rules, and add resources to a backend pool. For the sake of simplicity, this article uses a
simple setup with a public front-end IP, a basic listener to host a single site on the application gateway, a basic
request routing rule, and two virtual machines in the backend pool.
You can also complete this quickstart using Azure PowerShell or Azure CLI.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Prerequisites
An Azure account with an active subscription. Create an account for free.
NOTE
Virtual network service endpoint policies are currently not supported in an Application Gateway subnet.
Under Configure vir tual network , create a new virtual network by selecting Create new . In the
Create vir tual network window that opens, enter the following values to create the virtual network
and two subnets:
Name : Enter myVNet for the name of the virtual network.
Subnet name (Application Gateway subnet): The Subnets grid will show a subnet named
Default. Change the name of this subnet to myAGSubnet.
The application gateway subnet can contain only application gateways. No other resources are
allowed.
Subnet name (backend server subnet): In the second row of the Subnets grid, enter
myBackendSubnet in the Subnet name column.
Address range (backend server subnet): In the second row of the Subnets Grid, enter an address
range that doesn't overlap with the address range of myAGSubnet. For example, if the address
range of myAGSubnet is 10.0.0.0/24, enter 10.0.1.0/24 for the address range of
myBackendSubnet.
Select OK to close the Create vir tual network window and save the virtual network settings.
3. On the Basics tab, accept the default values for the other settings and then select Next: Frontends .
Frontends tab
1. On the Frontends tab, verify Frontend IP address type is set to Public .
You can configure the Frontend IP to be Public or Private as per your use case. In this example, you'll
choose a Public Frontend IP.
NOTE
For the Application Gateway v2 SKU, there must be a Public frontend IP configuration. You can still have both a
Public and a Private frontend IP configuration, but Private only frontend IP configuration (Only ILB mode) is
currently not enabled for the v2 SKU.
2. Select Add new for the Public IP address and enter myAGPublicIPAddress for the public IP address
name, and then select OK .
3. Select Next: Backends .
Backends tab
The backend pool is used to route requests to the backend servers that serve the request. Backend pools can be
composed of NICs, virtual machine scale sets, public IP addresses, internal IP addresses, fully qualified domain
names (FQDN), and multi-tenant back-ends like Azure App Service. In this example, you'll create an empty
backend pool with your application gateway and then add backend targets to the backend pool.
1. On the Backends tab, select Add a backend pool .
2. In the Add a backend pool window that opens, enter the following values to create an empty backend
pool:
Name : Enter myBackendPool for the name of the backend pool.
Add backend pool without targets : Select Yes to create a backend pool with no targets. You'll add
backend targets after creating the application gateway.
3. In the Add a backend pool window, select Add to save the backend pool configuration and return to
the Backends tab.
6. On the Add a routing rule window, select Add to save the routing rule and return to the
Configuration tab.
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-ExtensionName IIS `
-VMName myVM `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-
Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
-Location EastUS
3. Create a second virtual machine and install IIS by using the steps that you previously completed. Use
myVM2 for the virtual machine name and for the VMName setting of the Set-AzVMExtension cmdlet.
Add backend servers to backend pool
1. On the Azure portal menu, select All resources or search for and select All resources. Then select
myAppGateway .
2. Select Backend pools from the left menu.
3. Select myBackendPool .
4. Under Backend targets , Target type , select Vir tual machine from the drop-down list.
5. Under Target , select the myVM and myVM2 virtual machines and their associated network interfaces
from the drop-down lists.
6. Select Save .
7. Wait for the deployment to complete before proceeding to the next step.
Or, you can select All resources , enter myAGPublicIPAddress in the search box, and then select it in the
search results. Azure displays the public IP address on the Over view page.
2. Copy the public IP address, and then paste it into the address bar of your browser to browse that IP
address.
3. Check the response. A valid response verifies that the application gateway was successfully created and
can successfully connect with the backend.
Refresh the browser multiple times and you should see connections to both myVM and myVM2.
Clean up resources
When you no longer need the resources that you created with the application gateway, delete the resource
group. When you delete the resource group, you also remove the application gateway and all the related
resources.
To delete the resource group:
1. On the Azure portal menu, select Resource groups or search for and select Resource groups.
2. On the Resource groups page, search for myResourceGroupAG in the list, then select it.
3. On the Resource group page , select Delete resource group .
4. Enter myResourceGroupAG under TYPE THE RESOURCE GROUP NAME and then select Delete
Next steps
Tutorial: Configure an application gateway with TLS termination using the Azure portal
Quickstart: Direct web traffic with Azure Application
Gateway using Azure PowerShell
3/5/2021 • 7 minutes to read • Edit Online
In this quickstart, you use Azure PowerShell to create an application gateway. Then you test it to make sure it
works correctly.
The application gateway directs application web traffic to specific resources in a backend pool. You assign
listeners to ports, create rules, and add resources to a backend pool. For the sake of simplicity, this article uses a
simple setup with a public front-end IP address, a basic listener to host a single site on the application gateway, a
basic request routing rule, and two virtual machines in the backend pool.
You can also complete this quickstart using Azure CLI or the Azure portal.
Prerequisites
An Azure account with an active subscription. Create an account for free.
Azure PowerShell version 1.0.0 or later (if you run Azure PowerShell locally).
O P T IO N EXA M P L E/ L IN K
Connect to Azure
To connect with Azure, run Connect-AzAccount .
NOTE
Virtual network service endpoint policies are currently not supported in an Application Gateway subnet.
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.1.0/24
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.2.0/24
New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $agSubnetConfig, $backendSubnetConfig
New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Static `
-Sku Standard
Create an application gateway
Create the IP configurations and frontend port
1. Use New-AzApplicationGatewayIPConfiguration to create the configuration that associates the subnet you
created with the application gateway.
2. Use New-AzApplicationGatewayFrontendIPConfig to create the configuration that assigns the public IP address
that you previously created for the application gateway.
3. Use New-AzApplicationGatewayFrontendPort to assign port 80 to access the application gateway.
$backendPool = New-AzApplicationGatewayBackendAddressPool `
-Name myAGBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSetting `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 30
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name myAGListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $backendPool `
-BackendHttpSettings $poolSettings
Create the application gateway
Now that you've created the necessary supporting resources, create the application gateway:
1. Use New-AzApplicationGatewaySku to specify parameters for the application gateway.
2. Use New-AzApplicationGateway to create the application gateway.
$sku = New-AzApplicationGatewaySku `
-Name Standard_v2 `
-Tier Standard_v2 `
-Capacity 2
New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $backendPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku
Backend servers
Now that you have created the Application Gateway, create the backend virtual machines which will host the
websites. A backend can be composed of NICs, virtual machine scale sets, public IP address, internal IP address,
fully qualified domain names (FQDN), and multi-tenant back-ends like Azure App Service.
In this example, you create two virtual machines to use as backend servers for the application gateway. You also
install IIS on the virtual machines to verify that Azure successfully created the application gateway.
Create two virtual machines
1. Get the recently created Application Gateway backend pool configuration with
Get-AzApplicationGatewayBackendAddressPool .
2. Create a network interface with New-AzNetworkInterface .
3. Create a virtual machine configuration with New-AzVMConfig .
4. Create the virtual machine with New-AzVM .
When you run the following code sample to create the virtual machines, Azure prompts you for credentials.
Enter a user name and a password:
$appgw = Get-AzApplicationGateway -ResourceGroupName myResourceGroupAG -Name myAppGateway
$backendPool = Get-AzApplicationGatewayBackendAddressPool -Name myAGBackendPool -ApplicationGateway $appgw
$vnet = Get-AzVirtualNetwork -ResourceGroupName myResourceGroupAG -Name myVNet
$subnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name myBackendSubnet
$cred = Get-Credential
for ($i=1; $i -le 2; $i++)
{
$nic = New-AzNetworkInterface `
-Name myNic$i `
-ResourceGroupName myResourceGroupAG `
-Location EastUS `
-Subnet $subnet `
-ApplicationGatewayBackendAddressPool $backendpool
$vm = New-AzVMConfig `
-VMName myVM$i `
-VMSize Standard_DS2_v2
Set-AzVMOperatingSystem `
-VM $vm `
-Windows `
-ComputerName myVM$i `
-Credential $cred
Set-AzVMSourceImage `
-VM $vm `
-PublisherName MicrosoftWindowsServer `
-Offer WindowsServer `
-Skus 2016-Datacenter `
-Version latest
Add-AzVMNetworkInterface `
-VM $vm `
-Id $nic.Id
Set-AzVMBootDiagnostic `
-VM $vm `
-Disable
New-AzVM -ResourceGroupName myResourceGroupAG -Location EastUS -VM $vm
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-ExtensionName IIS `
-VMName myVM$i `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -
Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
-Location EastUS
}
Next steps
Manage web traffic with an application gateway using Azure PowerShell
Quickstart: Direct web traffic with Azure Application
Gateway - Azure CLI
3/5/2021 • 5 minutes to read • Edit Online
In this quickstart, you use Azure CLI to create an application gateway. Then you test it to make sure it works
correctly.
The application gateway directs application web traffic to specific resources in a backend pool. You assign
listeners to ports, create rules, and add resources to a backend pool. For the sake of simplicity, this article uses a
simple setup with a public front-end IP address, a basic listener to host a single site on the application gateway, a
basic request routing rule, and two virtual machines in the backend pool.
You can also complete this quickstart using Azure PowerShell or the Azure portal.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This article requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
Create the network interfaces with az network nic create . To create the virtual machines, you use az vm create
.
It can take up to 30 minutes for Azure to create the application gateway. After it's created, you can view the
following settings in the Settings section of the Application gateway page:
appGatewayBackendPool : Located on the Backend pools page. It specifies the required backend pool.
appGatewayBackendHttpSettings : Located on the HTTP settings page. It specifies that the application
gateway uses port 80 and the HTTP protocol for communication.
appGatewayHttpListener : Located on the Listeners page . It specifies the default listener associated with
appGatewayBackendPool .
appGatewayFrontendIP : Located on the Frontend IP configurations page. It assigns
myAGPublicIPAddress to appGatewayHttpListener .
rule1 : Located on the Rules page. It specifies the default routing rule that's associated with
appGatewayHttpListener .
Copy and paste the public IP address into the address bar of your browser.
When you refresh the browser, you should see the name of the second VM. This indicates the application
gateway was successfully created and can connect with the backend.
Clean up resources
When you no longer need the resources that you created with the application gateway, use the az group delete
command to delete the resource group. When you delete the resource group, you also delete the application
gateway and all its related resources.
Next steps
Manage web traffic with an application gateway using the Azure CLI
Quickstart: Direct web traffic with Azure Application
Gateway - ARM template
3/5/2021 • 5 minutes to read • Edit Online
In this quickstart, you use an Azure Resource Manager template (ARM template) to create an Azure Application
Gateway. Then you test the application gateway to make sure it works correctly.
An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for
your project. The template uses declarative syntax. In declarative syntax, you describe your intended deployment
without writing the sequence of programming commands to create the deployment.
You can also complete this quickstart using the Azure portal, Azure PowerShell, or Azure CLI.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to
Azure button. The template will open in the Azure portal.
Prerequisites
An Azure account with an active subscription. Create an account for free.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "Admin username for the backend servers"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the admin account on the backend servers"
}
},
"location": {
"type": "string",
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_B2ms",
"metadata": {
"description": "Size of the virtual machine."
}
}
},
"variables": {
"virtualMachines_myVM_name": "myVM",
"virtualNetworks_myVNet_name": "myVNet",
"net_interface": "net-int",
"ipconfig_name": "ipconfig",
"publicIPAddress": "public_ip",
"nsg_name": "vm-nsg",
"applicationGateways_myAppGateway_name": "myAppGateway",
"vnet_prefix": "10.0.0.0/16",
"ag_subnet_prefix": "10.0.0.0/24",
"backend_subnet_prefix": "10.0.1.0/24"
},
"resources": [
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-06-01",
"name": "[concat(variables('nsg_name'), copyIndex(1))]",
"location": "[parameters('location')]",
"copy": {
"name": "nsg-loop",
"count": 2
},
"properties": {
"securityRules": [
{
"name": "RDP",
"properties": {
"protocol": "TCP",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 300,
"direction": "Inbound"
}
}
]
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2020-06-01",
"name": "[concat(variables('publicIPAddress'), copyIndex())]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"copy": {
"name": "publicip-loop",
"count": 3
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static",
"idleTimeoutInMinutes": 4
"idleTimeoutInMinutes": 4
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-06-01",
"name": "[variables('virtualNetworks_myVNet_name')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('vnet_prefix')]"
]
},
"subnets": [
{
"name": "myAGSubnet",
"properties": {
"addressPrefix": "[variables('ag_subnet_prefix')]",
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
},
{
"name": "myBackendSubnet",
"properties": {
"addressPrefix": "[variables('backend_subnet_prefix')]",
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
}
],
"enableDdosProtection": false,
"enableVmProtection": false
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"name": "[concat(variables('virtualMachines_myVM_name'), copyIndex(1))]",
"location": "[parameters('location')]",
"copy": {
"name": "vm-loop",
"count": 2
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', concat(variables('net_interface'),
copyIndex(1)))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
},
"diskSizeGB": 127
}
},
"osProfile": {
"computerName": "[concat(variables('virtualMachines_myVM_name'), copyIndex(1))]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true
},
"allowExtensionOperations": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('net_interface'),
copyIndex(1)))]"
}
]
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2020-06-01",
"name": "[concat(variables('virtualMachines_myVM_name'), copyIndex(1),'/IIS')]",
"location": "[parameters('location')]",
"copy": {
"name": "ext-loop",
"count": 2
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', concat(variables('virtualMachines_myVM_name'),
copyIndex(1)))]"
],
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"settings": {
"commandToExecute": "powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path
\"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"
}
}
},
{
"type": "Microsoft.Network/applicationGateways",
"apiVersion": "2020-06-01",
"name": "[variables('applicationGateways_myAppGateway_name')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworks_myVNet_name'))]",
"[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('publicIPAddress'), '0'))]"
],
"properties": {
"sku": {
"name": "Standard_v2",
"tier": "Standard_v2"
},
"gatewayIPConfigurations": [
{
"name": "appGatewayIpConfig",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets',
variables('virtualNetworks_myVNet_name'), 'myAGSubnet')]"
}
}
}
],
"frontendIPConfigurations": [
{
"name": "appGwPublicFrontendIp",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',
concat(variables('publicIPAddress'), '0'))]"
}
}
}
],
"frontendPorts": [
{
"name": "port_80",
"properties": {
"port": 80
}
}
],
"backendAddressPools": [
{
"name": "myBackendPool",
"properties": {
}
}
],
"backendHttpSettingsCollection": [
{
"name": "myHTTPSetting",
"properties": {
"port": 80,
"protocol": "Http",
"cookieBasedAffinity": "Disabled",
"pickHostNameFromBackendAddress": false,
"requestTimeout": 20
}
}
],
"httpListeners": [
{
"name": "myListener",
"properties": {
"frontendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/applicationGateways/frontendIPConfigurations',
variables('applicationGateways_myAppGateway_name'), 'appGwPublicFrontendIp')]"
},
"frontendPort": {
"id": "[resourceId('Microsoft.Network/applicationGateways/frontendPorts',
variables('applicationGateways_myAppGateway_name'), 'port_80')]"
},
"protocol": "Http",
"requireServerNameIndication": false
}
}
],
"requestRoutingRules": [
{
"name": "myRoutingRule",
"properties": {
"ruleType": "Basic",
"httpListener": {
"id": "[resourceId('Microsoft.Network/applicationGateways/httpListeners',
variables('applicationGateways_myAppGateway_name'), 'myListener')]"
},
"backendAddressPool": {
"id": "[resourceId('Microsoft.Network/applicationGateways/backendAddressPools',
variables('applicationGateways_myAppGateway_name'), 'myBackendPool')]"
variables('applicationGateways_myAppGateway_name'), 'myBackendPool')]"
},
"backendHttpSettings": {
"id": "[resourceId('Microsoft.Network/applicationGateways/backendHttpSettingsCollection',
variables('applicationGateways_myAppGateway_name'), 'myHTTPSetting')]"
}
}
}
],
"enableHttp2": false,
"autoscaleConfiguration": {
"minCapacity": 0,
"maxCapacity": 10
}
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-06-01",
"name": "[concat(variables('net_interface'), copyIndex(1))]",
"location": "[parameters('location')]",
"copy": {
"name": "int-loop",
"count": 2
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('publicIPAddress'),
copyIndex(1)))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworks_myVNet_name'))]",
"[resourceId('Microsoft.Network/applicationGateways',
variables('applicationGateways_myAppGateway_name'))]",
"[resourceId('Microsoft.Network/networkSecurityGroups', concat(variables('nsg_name'),
copyIndex(1)))]"
],
"properties": {
"ipConfigurations": [
{
"name": "[concat(variables('ipconfig_name'), copyIndex(1))]",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',
concat(variables('publicIPAddress'), copyIndex(1)))]"
},
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets',
variables('virtualNetworks_myVNet_name'), 'myBackendSubnet')]"
},
"primary": true,
"privateIPAddressVersion": "IPv4",
"applicationGatewayBackendAddressPools": [
{
"id": "[resourceId('Microsoft.Network/applicationGateways/backendAddressPools',
variables('applicationGateways_myAppGateway_name'), 'myBackendPool')]"
}
]
}
}
],
"enableAcceleratedNetworking": false,
"enableIPForwarding": false,
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', concat(variables('nsg_name'),
copyIndex(1)))]"
}
}
}
]
}
Multiple Azure resources are defined in the template:
Microsoft.Network/applicationgateways
Microsoft.Network/publicIPAddresses : one for the application gateway, and two for the virtual
machines.
Microsoft.Network/networkSecurityGroups
Microsoft.Network/vir tualNetworks
Microsoft.Compute/vir tualMachines : two virtual machines
Microsoft.Network/networkInterfaces : two for the virtual machines
Microsoft.Compute/vir tualMachine/extensions : to configure IIS and the web pages
2. Select or create your resource group, type the virtual machine administrator user name and password.
3. Select Review + Create and then select Create .
The deployment can take 20 minutes or longer to complete.
Or, you can select All resources , enter myAGPublicIPAddress in the search box, and then select it in the
search results. Azure displays the public IP address on the Over view page.
2. Copy the public IP address, and then paste it into the address bar of your browser to browse that IP
address.
3. Check the response. A valid response verifies that the application gateway was successfully created and
can successfully connect with the backend.
Refresh the browser multiple times and you should see connections to both myVM1 and myVM2.
Clean up resources
When you no longer need the resources that you created with the application gateway, delete the resource
group. This removes the application gateway and all the related resources.
To delete the resource group, call the Remove-AzResourceGroup cmdlet:
Next steps
Manage web traffic with an application gateway using the Azure CLI
Tutorial: Configure an application gateway with TLS
termination using the Azure portal
3/5/2021 • 8 minutes to read • Edit Online
You can use the Azure portal to configure an application gateway with a certificate for TLS termination that uses
virtual machines for backend servers.
In this tutorial, you learn how to:
Create a self-signed certificate
Create an application gateway with the certificate
Create the virtual machines used as backend servers
Test the application gateway
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Prerequisites
Sign in to the Azure portal at https://portal.azure.com
New-SelfSignedCertificate `
-certstorelocation cert:\localmachine\my `
-dnsname www.contoso.com
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
Thumbprint Subject
---------- -------
E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 CN=www.contoso.com
Use Export-PfxCertificate with the Thumbprint that was returned to export a pfx file from the certificate. Make
sure your password is 4 - 12 characters long:
$pwd = ConvertTo-SecureString -String <your password> -Force -AsPlainText
Export-PfxCertificate `
-cert cert:\localMachine\my\E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 `
-FilePath c:\appgwcert.pfx `
-Password $pwd
3. On the Basics tab, accept the default values for the other settings and then select Next: Frontends .
Frontends tab
1. On the Frontends tab, verify Frontend IP address type is set to Public .
You can configure the Frontend IP to be Public or Private as per your use case. In this example, you'll
choose a Public Frontend IP.
NOTE
For the Application Gateway v2 SKU, you can only choose Public frontend IP configuration. Private frontend IP
configuration is currently not enabled for this v2 SKU.
2. Choose Add new for the Public IP address and enter myAGPublicIPAddress for the public IP address
name, and then select OK .
3. Select Next: Backends .
Backends tab
The backend pool is used to route requests to the backend servers that serve the request. Backend pools can be
composed of NICs, virtual machine scale sets, public IPs, internal IPs, fully qualified domain names (FQDN), and
multi-tenant back-ends like Azure App Service. In this example, you'll create an empty backend pool with your
application gateway and then add backend targets to the backend pool.
1. On the Backends tab, select Add a backend pool .
2. In the Add a backend pool window that opens, enter the following values to create an empty backend
pool:
Name : Enter myBackendPool for the name of the backend pool.
Add backend pool without targets : Select Yes to create a backend pool with no targets. You'll add
backend targets after creating the application gateway.
3. In the Add a backend pool window, select Add to save the backend pool configuration and return to
the Backends tab.
6. On the Add a routing rule window, select Add to save the routing rule and return to the
Configuration tab.
7. Select Next: Tags and then Next: Review + create .
Review + create tab
Review the settings on the Review + create tab, and then select Create to create the virtual network, the
public IP address, and the application gateway. It may take several minutes for Azure to create the application
gateway. Wait until the deployment finishes successfully before moving on to the next section.
2. Change the location setting for your environment, and then run the following command to install IIS on
the virtual machine:
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-ExtensionName IIS `
-VMName myVM `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell
Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
-Location <location>
3. Create a second virtual machine and install IIS by using the steps that you previously completed. Use
myVM2 for the virtual machine name and for the VMName setting of the Set-AzVMExtension cmdlet.
Add backend servers to backend pool
1. Select All resources , and then select myAppGateway .
2. Select Backend pools from the left menu.
3. Select myBackendPool .
4. Under Target type , select Vir tual machine from the drop-down list.
5. Under Target , select the the network interface under myVM from the drop-down list.
6. Repeat to add the network interface for myVM2 .
7. Select Save .
8. Wait for the deployment to complete before proceeding to the next step.
Next steps
Learn more about Application Gateway TLS support
Tutorial: Create and configure an application
gateway to host multiple web sites using the Azure
portal
3/20/2021 • 9 minutes to read • Edit Online
You can use the Azure portal to configure the hosting of multiple web sites when you create an application
gateway. In this tutorial, you define backend address pools using virtual machines. You then configure listeners
and rules based on two domains to make sure web traffic arrives at the appropriate servers in the pools. This
tutorial uses examples of www.contoso.com and www.fabrikam.com.
In this tutorial, you learn how to:
Create an application gateway
Create virtual machines for backend servers
Create backend pools with the backend servers
Create backend listeners
Create routing rules
Edit Hosts file for name resolution
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Sign in to the Azure portal at https://portal.azure.com.
2. For Azure to communicate between the resources that you create, it needs a virtual network. You can
either create a new virtual network or use an existing one. In this example, you'll create a new virtual
network at the same time that you create the application gateway. Application Gateway instances are
created in separate subnets. You create two subnets in this example: one for the application gateway, and
another for the backend servers.
Under Configure vir tual network , select Create new to create a new virtual network . In the Create
vir tual network window that opens, enter the following values to create the virtual network and two
subnets:
Name : Enter myVNet for the name of the virtual network.
Subnet name (Application Gateway subnet): The Subnets grid will show a subnet named
Default. Change the name of this subnet to myAGSubnet.
The application gateway subnet can contain only application gateways. No other resources are
allowed.
Subnet name (backend server subnet): In the second row of the Subnets grid, enter
myBackendSubnet in the Subnet name column.
Address range (backend server subnet): In the second row of the Subnets Grid, enter an address
range that doesn't overlap with the address range of myAGSubnet. For example, if the address
range of myAGSubnet is 10.0.0.0/24, enter 10.0.1.0/24 for the address range of
myBackendSubnet.
Select OK to close the Create vir tual network window and save the virtual network settings.
3. On the Basics tab, accept the default values for the other settings and then select Next: Frontends .
Frontends tab
1. On the Frontends tab, verify Frontend IP address type is set to Public .
You can configure the Frontend IP to be Public or Private as per your use case. In this example, you'll
choose a Public Frontend IP.
NOTE
For the Application Gateway v2 SKU, you can only choose Public frontend IP configuration. Private frontend IP
configuration is currently not enabled for this v2 SKU.
2. Select Add new for the Public IP address and enter myAGPublicIPAddress for the public IP address
name, and then select OK .
3. Select Next: Backends .
Backends tab
The backend pool is used to route requests to the backend servers that serve the request. Backend pools can be
NICs, virtual machine scale sets, public IPs, internal IPs, fully qualified domain names (FQDN), and multi-tenant
back-ends like Azure App Service. In this example, you'll create an empty backend pool with your application
gateway and then add backend targets to the backend pool.
1. On the Backends tab, select Add a backend pool .
2. In the Add a backend pool window that opens, enter the following values to create an empty backend
pool:
Name : Enter contosoPool for the name of the backend pool.
Add backend pool without targets : Select Yes to create a backend pool with no targets. You'll add
backend targets after creating the application gateway.
3. In the Add a backend pool window, select Add to save the backend pool configuration and return to
the Backends tab.
4. Now add another backend pool called fabrikamPool the same way that you added the previous pool.
5. Select Add .
2. Run the following command to install IIS on the virtual machine, substituting your resource group region
for <location>:
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-ExtensionName IIS `
-VMName contosoVM `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-
Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
-Location <location>
3. Create a second virtual machine and install IIS using the steps that you previously completed. Use
fabrikamVM for the virtual machine name and for the VMName setting of the Set-AzVMExtension
cmdlet.
Add backend servers to backend pools
1. Select All resources , and then select myAppGateway .
2. Select Backend pools from the left menu.
3. Select contosoPool .
4. Under Target type , select Vir tual machine from the drop-down list.
5. Under Target , select the contosoVM virtual machine's network interface from the drop-down list.
6. Select Save .
7. Repeat to add the fabrikamVM and interface to the fabrikamPool.
Wait for the deployment to complete before proceeding to the next step.
Edit your hosts file for name resolution
After the application gateway is created with its public IP address, you can get the IP address and use it to edit
your hosts file to resolve www.contoso.com and www.fabrikam.com . In a production environment, you could create
a CNAME in DNS for name resolution.
1. Click All resources , and then click myAGPublicIPAddress .
2. Copy the IP address and use it as the value for new entries your hosts file.
3. On your local machine, open an administrative command prompt, and navigate to
c:\Windows\System32\drivers\etc .
4. Open the hosts file, and add the following entries, where x.x.x.x is the application gateway's public IP
address:
ipconfig/registerdns
ipconfig/displaydns
2. Change the address to the other domain and you should see something like the following example:
Clean up resources
When you no longer need the resources that you created with the application gateway, remove the resource
group. When you remove the resource group, you also remove the application gateway and all its related
resources.
To remove the resource group:
1. On the left menu of the Azure portal, select Resource groups .
2. On the Resource groups page, search for myResourceGroupAG in the list, then select it.
3. On the Resource group page , select Delete resource group .
4. Enter myResourceGroupAG for TYPE THE RESOURCE GROUP NAME and then select Delete .
To restore the hosts file:
1. Delete the www.contoso.com and www.fabrikam.com lines from the hosts file and run ipconfig/registerdns
and ipconfig/flushdns from the command prompt.
Next steps
Learn more about what you can do with Azure Application Gateway
Tutorial: Create an application gateway with path-
based routing rules using the Azure portal
3/5/2021 • 6 minutes to read • Edit Online
You can use the Azure portal to configure URL path-based routing rules when you create an application
gateway. In this tutorial, you create backend pools using virtual machines. You then create routing rules that
make sure web traffic arrives at the appropriate servers in the pools.
In this article, you learn how to:
Create an application gateway
Create virtual machines for backend servers
Create backend pools with the backend servers
Create a backend listener
Create a path-based routing rule
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Prerequisites
If you don't have an Azure subscription, create a free account before you begin.
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-ExtensionName IIS `
-VMName myVM1 `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-Settings $publicSettings
3. Install IIS on the other virtual machines using the steps that you just finished. Use myVM2 and myVM3
for VMName values in Set-AzVMExtension.
NOTE
For the Application Gateway v2 SKU, you can only choose Public frontend IP configuration. Private frontend IP
configuration is currently not enabled for this v2 SKU.
2. Select Add new for the Public IP address and enter myAGPublicIPAddress for the public IP address
name, and then select OK .
3. Select Next: Backends .
Backends tab
The backend pool is used to route requests to the backend servers that serve the request. Backend pools can be
composed of NICs, virtual machine scale sets, public IPs, internal IPs, fully qualified domain names (FQDN), and
multi-tenant back-ends like Azure App Service.
1. On the Backends tab, select Add a backend pool .
2. In the Add a backend pool window that opens, enter the following values to create an empty backend
pool:
Name : Enter myBackendPool for the name of the backend pool.
3. Under Target type , select Vir tual machine from the drop-down list.
4. Under Target select the network interface for myVM1 .
5. Select Add .
6. Repeat to add an Images backend pool with myVM2 as the target, and a Video backend pool with
myVM3 as the target.
7. Select Add to save the backend pool configuration and return to the Backends tab.
8. On the Backends tab, select Next: Configuration .
Configuration tab
On the Configuration tab, you'll connect the frontend and backend pool you created using a routing rule.
1. Select Add a routing rule in the Routing rules column.
2. In the Add a routing rule window that opens, enter myRoutingRule for the Rule name .
3. A routing rule requires a listener. On the Listener tab within the Add a routing rule window, type the
following values for the listener:
Listener name : Enter myListener for the name of the listener.
Frontend IP : Select Public to choose the public IP you created for the frontend.
Por t : Type 8080
Accept the default values for the other settings on the Listener tab, then select the Backend
targets tab to configure the rest of the routing rule.
4. On the Backend targets tab, select myBackendPool for the Backend target .
5. For the HTTP setting , select Add new to create a new HTTP setting. The HTTP setting will determine the
behavior of the routing rule.
6. In the Add an HTTP setting window that opens, enter myHTTPSetting for the HTTP setting name .
Accept the default values for the other settings in the Add an HTTP setting window, then select Add to
return to the Add a routing rule window.
7. Under Path-based routing , select Add multiple targets to create a path-based rule .
8. For Path , type /images/*.
9. For Target name , type Images.
10. For HTTP setting , select myHTTPSetting
11. For Backend target , select Images .
12. Select Add to save the path rule and return to the Add a routing rule tab.
13. Repeat to add another rule for Video.
14. Select Add to add the routing rule and return to the Configuration tab.
15. Select Next: Tags and then Next: Review + create .
NOTE
You do not need to add a custom /* path rule to handle default cases. This is automatically handled by the default
backend pool.
2. Copy the public IP address, and then paste it into the address bar of your browser. Such as,
http://52.188.72.175:8080.
The listener on port 8080 routes this request to the default backend pool.
3. Change the URL to http://<ip-address>:8080/images/test.htm, replacing <ip-address> with your IP
address, and you should see something like the following example:
The listener on port 8080 routes this request to the Images backend pool.
4. Change the URL to http://<ip-address>:8080/video/test.htm, replacing <ip-address> with your IP
address, and you should see something like the following example:
The listener on port 8080 routes this request to the Video backend pool.
Clean up resources
When no longer needed, delete the resource group and all related resources. To do so, select the resource group
and select Delete resource group .
Next steps
Enable end to end TLS on Azure Application Gateway
Tutorial: Create an application gateway with URL
path-based redirection using the Azure CLI
3/5/2021 • 6 minutes to read • Edit Online
You can use the Azure CLI to configure URL path-based routing rules when you create an application gateway. In
this tutorial, you create backend pools using virtual machine scale sets. You then create URL routing rules that
make sure web traffic is redirected to the appropriate backend pool.
In this tutorial, you learn how to:
Set up the network
Create an application gateway
Add listeners and routing rules
Create virtual machine scale sets for backend pools
The following example shows site traffic coming from both ports 8080 and 8081 and being directed to the same
backend pools:
If you prefer, you can complete this tutorial using Azure PowerShell.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
Create a resource group
A resource group is a logical container into which Azure resources are deployed and managed. Create a
resource group using az group create.
The following example creates a resource group named myResourceGroupAG in the eastus location.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
Add backend pools and ports
You can add backend address pools named imagesBackendPool and videoBackendPool to your application
gateway by using az network application-gateway address-pool create. You add the frontend ports for the pools
using az network application-gateway frontend-port create.
az vmss create \
--name myvmss$i \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username <azure-user> \
--admin-password <password> \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name $poolName
done
Install NGINX
for i in `seq 1 3`; do
az vmss extension set \
--publisher Microsoft.Azure.Extensions \
--version 2.0 \
--name CustomScript \
--resource-group myResourceGroupAG \
--vmss-name myvmss$i \
--settings '{ "fileUris": ["https://raw.githubusercontent.com/Azure/azure-docs-powershell-
samples/master/application-gateway/iis/install_nginx.sh"], "commandToExecute": "./install_nginx.sh" }'
done
Change the URL to http://<ip-address>:8080/images/test.html, replacing your IP address for <ip-address>, and
you should see something like the following example:
Change the URL to http://<ip-address>:8080/video/test.html, replacing your IP address for <ip-address>, and
you should see something like the following example:
Now, change the URL to http://<ip-address>:8081/images/test.htm, replacing your IP address for <ip-address>,
and you should see traffic redirected back to the images backend pool at http://<ip-address>:8080/images.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources.
Next steps
Learn more about what you can do with application gateway
Tutorial: Create an application gateway that
improves web application access
3/8/2021 • 4 minutes to read • Edit Online
If you're an IT admin concerned with improving web application access, you can optimize your application
gateway to scale based on customer demand and span multiple availability zones. This tutorial helps you
configure Azure Application Gateway features that do that: autoscaling, zone redundancy, and reserved VIPs
(static IP). You'll use Azure PowerShell cmdlets and the Azure Resource Manager deployment model to solve the
problem.
In this tutorial, you learn how to:
Create a self-signed certificate
Create an autoscale virtual network
Create a reserved public IP
Set up your application gateway infrastructure
Specify autoscale
Create the application gateway
Test the application gateway
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This tutorial requires that you run an administrative Azure PowerShell session locally. You must have Azure
PowerShell module version 1.0.0 or later installed. Run Get-Module -ListAvailable Az to find the version. If you
need to upgrade, see Install Azure PowerShell module. After you verify the PowerShell version, run
Connect-AzAccount to create a connection with Azure.
Sign in to Azure
Connect-AzAccount
Select-AzSubscription -Subscription "<sub name>"
New-SelfSignedCertificate `
-certstorelocation cert:\localmachine\my `
-dnsname www.contoso.com
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
Thumbprint Subject
---------- -------
E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 CN=www.contoso.com
Use the thumbprint to create the pfx file. Replace <password> with a password of your choice:
Export-PfxCertificate `
-cert cert:\localMachine\my\E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 `
-FilePath c:\appgwcert.pfx `
-Password $pwd
Specify autoscale
Now you can specify the autoscale configuration for the application gateway.
Clean up resources
First explore the resources that were created with the application gateway. Then, when they're no longer needed,
you can use the Remove-AzResourceGroup command to remove the resource group, application gateway, and all
related resources.
Remove-AzResourceGroup -Name $rg
Next steps
Create an application gateway with URL path-based routing rules
Tutorial: Enable the Ingress Controller add-on for a
new AKS cluster with a new Application Gateway
instance
3/5/2021 • 4 minutes to read • Edit Online
You can use the Azure CLI to enable the Application Gateway Ingress Controller (AGIC) add-on for a new Azure
Kubernetes Services (AKS) cluster.
In this tutorial, you'll create an AKS cluster with the AGIC add-on enabled. Creating the cluster will automatically
create an Azure Application Gateway instance to use. You'll then deploy a sample application that will use the
add-on to expose the application through Application Gateway.
The add-on provides a much faster way to deploy AGIC for your AKS cluster than previously through Helm. It
also offers a fully managed experience.
In this tutorial, you learn how to:
Create a resource group.
Create a new AKS cluster with the AGIC add-on enabled.
Deploy a sample application by using AGIC for ingress on the AKS cluster.
Check that the application is reachable through Application Gateway.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
NOTE
The Application Gateway Ingress Controller add-on supports only Application Gateway v2 SKUs (Standard and WAF), and
not the Application Gateway v1 SKUs. When you're deploying a new Application Gateway instance through the AGIC
add-on, you can deploy only an Application Gateway Standard_v2 SKU. If you want to enable the add-on for an
Application Gateway WAF_v2 SKU, use either of these methods:
Enable WAF on Application Gateway through the portal.
Create the WAF_v2 Application Gateway instance first, and then follow instructions on how to enable the AGIC add-on
with an existing AKS cluster and existing Application Gateway instance.
In the following example, you'll deploy a new AKS cluster named myCluster by using Azure CNI and managed
identities. The AGIC add-on will be enabled in the resource group that you created, myResourceGroup.
Deploying a new AKS cluster with the AGIC add-on enabled without specifying an existing Application Gateway
instance will mean an automatic creation of a Standard_v2 SKU Application Gateway instance. So, you'll also
specify the name and subnet address space of the Application Gateway instance. The name of the Application
Gateway instance will be myApplicationGateway, and the subnet address space we're using is 10.2.0.0/16.
To configure additional parameters for the az aks create command, see these references.
NOTE
The AKS cluster that you created will appear in the resource group that you created, myResourceGroup. However, the
automatically created Application Gateway instance will be in the node resource group, where the agent pools are. The
node resource group by is named MC_resource-group-name_cluster-name_location by default, but can be modified.
Now that you have credentials, run the following command to set up a sample application that uses AGIC for
ingress to the cluster. AGIC will update the Application Gateway instance that you set up earlier with
corresponding routing rules to the new sample application that you deployed.
Check that the sample application that you created is running by either:
Visiting the IP address of the Application Gateway instance that you got from running the preceding
command.
Using curl .
Application Gateway might take a minute to get the update. If Application Gateway is still in an Updating state
on the portal, let it finish before you try to reach the IP address.
Clean up resources
When you no longer need them, remove the resource group, the Application Gateway instance, and all related
resources:
Next steps
Learn about disabling the AGIC add-on
Tutorial: Enable Application Gateway Ingress
Controller add-on for an existing AKS cluster with
an existing Application Gateway
3/5/2021 • 6 minutes to read • Edit Online
You can use Azure CLI or Portal to enable the Application Gateway Ingress Controller (AGIC) add-on for an
existing Azure Kubernetes Services (AKS) cluster. In this tutorial, you'll learn how to use AGIC add-on to expose
your Kubernetes application in an existing AKS cluster through an existing Application Gateway deployed in
separate virtual networks. You'll start by creating an AKS cluster in one virtual network and an Application
Gateway in a separate virtual network to simulate existing resources. You'll then enable the AGIC add-on, peer
the two virtual networks together, and deploy a sample application that will be exposed through the Application
Gateway using the AGIC add-on. If you're enabling the AGIC add-on for an existing Application Gateway and
existing AKS cluster in the same virtual network, then you can skip the peering step below. The add-on provides
a much faster way of deploying AGIC for your AKS cluster than previously through Helm and also offers a fully
managed experience.
In this tutorial, you learn how to:
Create a resource group
Create a new AKS cluster
Create a new Application Gateway
Enable the AGIC add-on in the existing AKS cluster through Azure CLI
Enable the AGIC add-on in the existing AKS cluster through Portal
Peer the Application Gateway virtual network with the AKS cluster virtual network
Deploy a sample application using AGIC for Ingress on the AKS cluster
Check that the application is reachable through Application Gateway
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
To configure additional parameters for the az aks create command, visit references here.
NOTE
Application Gateway Ingress Controller (AGIC) add-on only supports Application Gateway v2 SKUs (Standard and WAF),
and not the Application Gateway v1 SKUs.
Enable the AGIC add-on in existing AKS cluster through Azure CLI
If you'd like to continue using Azure CLI, you can continue to enable the AGIC add-on in the AKS cluster you
created, myCluster, and specify the AGIC add-on to use the existing Application Gateway you created,
myApplicationGateway.
Once you have the credentials to the cluster you created, run the following command to set up a sample
application that uses AGIC for Ingress to the cluster. AGIC will update the Application Gateway you set up earlier
with corresponding routing rules to the new sample application you deployed.
Check that the sample application you created is up and running by either visiting the IP address of the
Application Gateway that you got from running the above command or check with curl . It may take
Application Gateway a minute to get the update, so if the Application Gateway is still in an "Updating" state on
Portal, then let it finish before trying to reach the IP address.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources.
Next steps
Learn more about disabling the AGIC add-on
Azure PowerShell examples for Azure Application
Gateway (AG)
11/2/2020 • 2 minutes to read • Edit Online
The following table includes links to Azure PowerShell script examples for Azure Application Gateway.
Manage web traffic Creates an Application Gateway and all related resources.
Restrict web traffic Creates an Application Gateway that restricts traffic using
OWASP rules.
The following table includes links to Azure CLI script examples for Azure Application Gateway.
Manage web traffic Creates an application gateway and all related resources.
Restrict web traffic Creates an application gateway that restricts traffic using
OWASP rules.
Azure Resource Manager templates for Azure
Application Gateway
11/2/2020 • 2 minutes to read • Edit Online
The following table includes links to Azure Resource Manager templates for Azure Application Gateway.
Application Gateway v2 with Web Application Firewall Creates an Application Gateway v2 with Web Application
Firewall v2.
Working remotely using Azure networking services
3/5/2021 • 7 minutes to read • Edit Online
NOTE
This article describes how you can leverage Azure networking services, Microsoft network, and the Azure partner
ecosystem to work remotely and mitigate network issues that you might be facing because of the COVID-19 crisis.
This article describes the options that are available to organizations to set up remote access for their users or to
supplement their existing solutions with additional capacity during periods of peak utilization. Network
architects are faced with the following challenges:
Address an increase in network utilization.
Provide reliable-secure connectivity to more employees of their company and customers.
Provide connectivity to remote locations across the globe.
Not all networks (for example, private WAN and corporate core networks) experience congestion from peak
remote worker load. The bottlenecks are commonly reported only in home broadband networks and VPN
gateways of on-premises networks of corporations.
Network planners can help ease the bottlenecks and alleviate the network congestion by keeping in mind that
different traffic types need different network treatment priorities and by some smart load
redirection/distribution. For example, real-time tele-medecine traffic of doctor-patient interaction is of high
importance and delay/jitter sensitive. Whereas, replication of the same traffic between storages is not delay
sensitive. The former traffic must be routed via the most optimal network path with higher quality of service;
whereas it is acceptable to route the later traffic via sub-optimal route.
NOTE
Using the Azure networking features described below leverages the traffic attraction behavior of the Microsoft global
network to provide a better customer networking experience. The traffic attraction behavior of the Microsoft network
helps off loading traffic as soon as possible from the first/last mile networks that may experience congestion during
periods of peak utilization.
Enable employees to work remotely
Azure VPN gateway supports both Point-to-Site (P2S) and Site-to-Site (S2S) VPN connections. Using the Azure
VPN gateway you can scale your employee's connections to securely access both your Azure deployed resources
and your on-premises resources. For more information, see How to enable users to work remotely.
If you are using Secure Sockets Tunneling Protocol (SSTP), the number of concurrent connections is limited to
128. To get a higher number of connections, we suggest transitioning to OpenVPN or IKEv2. For more
information, see Transition to OpenVPN protocol or IKEv2 from SSTP.
To access your resources deployed in Azure, remote developers could use Azure Bastion solution, instead of VPN
connection to get secure shell access (RDP or SSH) without requiring public IPs on the VMs being accessed. For
more information, see Work remotely using Azure Bastion.
For aggregating large-scale VPN connection, to support any-to-any connections between resources in different
on-premises global locations, in different regional hub and spoke virtual networks, and to optimize utilization of
multiple home broadband networks you can use Azure Virtual WAN. For more information, see Struggling to
cater to work from home needs? Here is where Azure Virtual WAN can help.
Another way to support a remote workforce is to deploy a Virtual Desktop Infrastructure (VDI) hosted in your
Azure virtual network, secured with an Azure Firewall. For example, Windows Virtual Desktop (WVD) is a
desktop and app virtualization service that runs in Azure. With Windows Virtual Desktop, you can set up a
scalable and flexible environment in your Azure subscription without the need to run any additional gateway
servers. You are only responsible for the WVD virtual machines in your virtual network. For more information,
see Azure Firewall remote work support.
Azure also has a rich set of eco system partners. Our partners Network Virtual Appliances on Azure can also
help scale VPN connectivity. For more information, see Network Virtual Appliance (NVA) considerations for
remote work.
Next steps
The following articles discuss how different Azure networking features can be used to scale users to work
remotely:
A RT IC L E DESC RIP T IO N
How to enable users to work remotely Review available options to set up remote access for users or
to supplement their existing solutions with additional
capacity for your organization.
Struggling to cater to work from home needs? Here is where Use Azure Virtual WAN to address the remote connectivity
Azure Virtual WAN can help needs of your organization.
Application Gateway high traffic support Use Application Gateway with Web Application Firewall
(WAF) for a scalable and secure way to manage traffic to
your web applications.
Network Virtual Appliance (NVA) considerations for remote Review guidance about leveraging NVAs in Azure to provide
work remote access solutions.
Transition to OpenVPN protocol or IKEv2 from SSTP Overcome the 128 concurrent connection limit of SSTP by
transitioning to OpenVPN protocol or IKEv2.
Working remotely using Azure Bastion Provide secure and seamless RDP/SSH connectivity to virtual
machines within the Azure virtual network, directly in the
Azure portal, without the use of a public IP address.
Using Azure ExpressRoute to create hybrid connectivity to Use ExpressRoute for hybrid connectivity to enable users in
support remote users your organization to work remotely.
Azure Firewall remote work support Protect your Azure virtual network resources using Azure
Firewall.
Azure Application Gateway features
11/2/2020 • 8 minutes to read • Edit Online
Azure Application Gateway is a web traffic load balancer that enables you to manage traffic to your web
applications.
Autoscaling
Application Gateway Standard_v2 supports autoscaling and can scale up or down based on changing traffic load
patterns. Autoscaling also removes the requirement to choose a deployment size or instance count during
provisioning.
For more information about the Application Gateway Standard_v2 features, see Autoscaling v2 SKU.
Zone redundancy
A Standard_v2 Application Gateway can span multiple Availability Zones, offering better fault resiliency and
removing the need to provision separate Application Gateways in each zone.
Static VIP
The application gateway Standard_v2 SKU supports static VIP type exclusively. This ensures that the VIP
associated with application gateway doesn't change even over the lifetime of the Application Gateway.
URL-based routing
URL Path Based Routing allows you to route traffic to back-end server pools based on URL Paths of the request.
One of the scenarios is to route requests for different content types to different pool.
For example, requests for are routed to VideoServerPool, and
http://contoso.com/video/*
http://contoso.com/images/* are routed to ImageServerPool. DefaultServerPool is selected if none of the path
patterns match.
For more information, see URL Path Based Routing overview.
Multiple-site hosting
With Application Gateway, you can configure routing based on host name or domain name for more than one
web application on the same application gateway. It allows you to configure a more efficient topology for your
deployments by adding up to 100+ websites to one application gateway. Each website can be directed to its own
backend pool. For example, three domains, contoso.com, fabrikam.com, and adatum.com, point to the IP address
of the application gateway. You'd create three multi-site listeners and configure each listener for the respective
port and protocol setting.
Requests for http://contoso.com are routed to ContosoServerPool, http://fabrikam.com are routed to
FabrikamServerPool, and so on.
Similarly, two subdomains of the same parent domain can be hosted on the same application gateway
deployment. Examples of using subdomains could include http://blog.contoso.com and
http://app.contoso.com hosted on a single application gateway deployment. For more information, see
Application Gateway multiple site hosting.
You can also define wildcard host names in a multi-site listener and up to 5 host names per listener. To learn
more, see wildcard host names in listener (preview).
Redirection
A common scenario for many web applications is to support automatic HTTP to HTTPS redirection to ensure all
communication between an application and its users occurs over an encrypted path.
In the past, you may have used techniques such as dedicated pool creation whose sole purpose is to redirect
requests it receives on HTTP to HTTPS. Application gateway supports the ability to redirect traffic on the
Application Gateway. This simplifies application configuration, optimizes the resource usage, and supports new
redirection scenarios, including global and path-based redirection. Application Gateway redirection support isn't
limited to HTTP to HTTPS redirection alone. This is a generic redirection mechanism, so you can redirect from
and to any port you define using rules. It also supports redirection to an external site as well.
Application Gateway redirection support offers the following capabilities:
Global redirection from one port to another port on the Gateway. This enables HTTP to HTTPS redirection on
a site.
Path-based redirection. This type of redirection enables HTTP to HTTPS redirection only on a specific site area,
for example a shopping cart area denoted by /cart/* .
Redirect to an external site.
For more information, see Application Gateway redirect overview.
Session affinity
The cookie-based session affinity feature is useful when you want to keep a user session on the same server. By
using gateway-managed cookies, the Application Gateway can direct subsequent traffic from a user session to
the same server for processing. This is important in cases where session state is saved locally on the server for a
user session.
For more information, see How an application gateway works.
Connection draining
Connection draining helps you achieve graceful removal of backend pool members during planned service
updates. This setting is enabled via the backend http setting and can be applied to all members of a backend
pool during rule creation. Once enabled, Application Gateway ensures all deregistering instances of a backend
pool don't receive any new request while allowing existing requests to complete within a configured time limit.
This applies to both backend instances that are explicitly removed from the backend pool by a user
configuration change, and backend instances that are reported as unhealthy as determined by the health
probes. The only exception to this are requests bound for deregistering instances, which have been deregistered
explicitly, because of gateway-managed session affinity and continues to be proxied to the deregistering
instances.
For more information, see Application Gateway Configuration Overview.
Sizing
Application Gateway Standard_v2 can be configured for autoscaling or fixed size deployments. The v2 SKU
doesn't offer different instance sizes. For more information on v2 performance and pricing, see Autoscaling V2
and Understanding pricing.
The Application Gateway Standard (v1) is offered in three sizes: Small , Medium , and Large . Small instance
sizes are intended for development and testing scenarios.
For a complete list of application gateway limits, see Application Gateway service limits.
The following table shows an average performance throughput for each application gateway v1 instance with
SSL offload enabled:
AVERA GE B A C K - EN D PA GE
RESP O N SE SIZ E SM A L L M EDIUM L A RGE
NOTE
These values are approximate values for an application gateway throughput. The actual throughput depends on various
environment details, such as average page size, location of back-end instances, and processing time to serve a page. For
exact performance numbers, you should run your own tests. These values are only provided for capacity planning
guidance.
Next steps
Learn how Application Gateway works - How an application gateway works
How an application gateway works
3/18/2021 • 4 minutes to read • Edit Online
This article explains how an application gateway accepts incoming requests and routes them to the backend.
NOTE
Rules are processed in the order they're listed in the portal for v1 SKU.
When the application gateway selects the backend pool, it sends the request to one of the healthy backend
servers in the pool (y.y.y.y). The health of the server is determined by a health probe. If the backend pool
contains multiple servers, the application gateway uses a round-robin algorithm to route the requests between
healthy servers. This load balances the requests on the servers.
After the application gateway determines the backend server, it opens a new TCP session with the backend
server based on HTTP settings. HTTP settings specify the protocol, port, and other routing-related settings that
are required to establish a new session with the backend server.
The port and protocol used in HTTP settings determine whether the traffic between the application gateway and
backend servers is encrypted (thus accomplishing end-to-end TLS) or is unencrypted.
When an application gateway sends the original request to the backend server, it honors any custom
configuration made in the HTTP settings related to overriding the hostname, path, and protocol. This action
maintains cookie-based session affinity, connection draining, host-name selection from the backend, and so on.
NOTE
If the backend pool:
Is a public endpoint , the application gateway uses its frontend public IP to reach the server. If there isn't a frontend
public IP address, one is assigned for the outbound external connectivity.
Contains an internally resolvable FQDN or a private IP address , the application gateway routes the request
to the backend server by using its instance private IP addresses.
Contains an external endpoint or an externally resolvable FQDN, the application gateway routes the request
to the backend server by using its frontend public IP address. The DNS resolution is based on a private DNS zone or
custom DNS server, if configured, or it uses the default Azure-provided DNS. If there isn't a frontend public IP address,
one is assigned for the outbound external connectivity.
Next steps
Learn about application gateway components
Application gateway components
11/2/2020 • 8 minutes to read • Edit Online
An application gateway serves as the single point of contact for clients. It distributes incoming application traffic
across multiple backend pools, which include Azure VMs, virtual machine scale sets, Azure App Service, and on-
premises/external servers. To distribute traffic, an application gateway uses several components described in
this article.
Frontend IP addresses
A frontend IP address is the IP address associated with an application gateway. You can configure an application
gateway to have a public IP address, a private IP address, or both. An application gateway supports one public or
one private IP address. Your virtual network and public IP address must be in the same location as your
application gateway. After it's created, a frontend IP address is associated with a listener.
Static versus dynamic public IP address
The Azure Application Gateway V2 SKU can be configured to support either both static internal IP address and
static public IP address, or only static public IP address. It cannot be configured to support only static internal IP
address.
The V1 SKU can be configured to support static or dynamic internal IP address and dynamic public IP address.
The dynamic IP address of Application Gateway does not change on a running gateway. It can change only when
you stop or start the Gateway. It does not change on system failures, updates, Azure host updates etc.
The DNS name associated with an application gateway doesn't change over the lifecycle of the gateway. As a
result, you should use a CNAME alias and point it to the DNS address of the application gateway.
Listeners
A listener is a logical entity that checks for incoming connection requests. A listener accepts a request if the
protocol, port, hostname, and IP address associated with the request match the same elements associated with
the listener configuration.
Before you use an application gateway, you must add at least one listener. There can be multiple listeners
attached to an application gateway, and they can be used for the same protocol.
After a listener detects incoming requests from clients, the application gateway routes these requests to
members in the backend pool configured in the rule.
Listeners support the following ports and protocols.
Ports
A port is where a listener listens for the client request. You can configure ports ranging from 1 to 65502 for the
v1 SKU and 1 to 65199 for the v2 SKU.
Protocols
Application Gateway supports four protocols: HTTP, HTTPS, HTTP/2, and WebSocket:
NOTE
HTTP/2 protocol support is available to clients connecting to application gateway listeners only. The communication to
backend server pools is always over HTTP/1.1. By default, HTTP/2 support is disabled. You can choose to enable it.
Specify between the HTTP and HTTPS protocols in the listener configuration.
Support for WebSockets and HTTP/2 protocols is provided natively, and WebSocket support is enabled by
default. There's no user-configurable setting to selectively enable or disable WebSocket support. Use
WebSockets with both HTTP and HTTPS listeners.
Use an HTTPS listener for TLS termination. An HTTPS listener offloads the encryption and decryption work to
your application gateway, so your web servers aren't burdened by the overhead.
Custom error pages
Application Gateway lets you create custom error pages instead of displaying default error pages. You can use
your own branding and layout using a custom error page. Application Gateway displays a custom error page
when a request can't reach the backend.
For more information, see Custom error pages for your application gateway.
Types of listeners
There are two types of listeners:
Basic . This type of listener listens to a single domain site, where it has a single DNS mapping to the IP
address of the application gateway. This listener configuration is required when you host a single site
behind an application gateway.
Multi-site . This listener configuration is required when you want to configure routing based on host
name or domain name for more than one web application on the same application gateway. It allows you
to configure a more efficient topology for your deployments by adding up to 100+ websites to one
application gateway. Each website can be directed to its own backend pool. For example, three domains,
contoso.com, fabrikam.com, and adatum.com, point to the IP address of the application gateway. You'd
create three multi-site listeners and configure each listener for the respective port and protocol setting.
You can also define wildcard host names in a multi-site listener and up to 5 host names per listener. To
learn more, see wildcard host names in listener (preview).
For more information on how to configure a multi-site listener, see Multiple-site hosting in Application
Gateway using Azure portal.
After you create a listener, you associate it with a request routing rule. This rule determines how the request
received on the listener should be routed to the backend. The request routing rule also contains the backend
pool to be routed to and the HTTP setting where the backend port, protocol, etc. are mentioned.
HTTP settings
An application gateway routes traffic to the backend servers (specified in the request routing rule that include
HTTP settings) by using the port number, protocol, and other settings detailed in this component.
The port and protocol used in the HTTP settings determine whether the traffic between the application gateway
and backend servers is encrypted (providing end-to-end TLS) or unencrypted.
This component is also used to:
Determine whether a user session is to be kept on the same server by using the cookie-based session
affinity.
Gracefully remove backend pool members by using connection draining.
Associate a custom probe to monitor the backend health, set the request timeout interval, override host
name and path in the request, and provide one-click ease to specify settings for the App Service backend.
Backend pools
A backend pool routes request to backend servers, which serve the request. Backend pools can contain:
NICs
Virtual machine scale sets
Public IP addresses
Internal IP addresses
FQDN
Multitenant backends (such as App Service)
Application Gateway backend pool members aren't tied to an availability set. An application gateway can
communicate with instances outside of the virtual network that it's in. As a result, the members of the backend
pools can be across clusters, across datacenters, or outside Azure, as long as there's IP connectivity.
If you use internal IPs as backend pool members, you must use virtual network peering or a VPN gateway.
Virtual network peering is supported and beneficial for load-balancing traffic in other virtual networks.
An application gateway can also communicate with to on-premises servers when they're connected by Azure
ExpressRoute or VPN tunnels if traffic is allowed.
You can create different backend pools for different types of requests. For example, create one backend pool for
general requests, and then another backend pool for requests to the microservices for your application.
Health probes
By default, an application gateway monitors the health of all resources in its backend pool and automatically
removes unhealthy ones. It then monitors unhealthy instances and adds them back to the healthy backend pool
when they become available and respond to health probes.
In addition to using default health probe monitoring, you can also customize the health probe to suit your
application's requirements. Custom probes allow more granular control over the health monitoring. When using
custom probes, you can configure a custom hostname, URL path, probe interval, and how many failed
responses to accept before marking the back-end pool instance as unhealthy, custom status codes and response
body match, etc. We recommend that you configure custom probes to monitor the health of each backend pool.
For more information, see Monitor the health of your application gateway.
Next steps
Create an application gateway:
In the Azure portal
By using Azure PowerShell
By using the Azure CLI
Application Gateway configuration overview
11/2/2020 • 2 minutes to read • Edit Online
Azure Application Gateway consists of several components that you can configure in various ways for different
scenarios. This article shows you how to configure each component.
This image illustrates an application that has three listeners. The first two are multi-site listeners for
http://acme.com/* and http://fabrikam.com/* , respectively. Both listen on port 80. The third is a basic listener
that has end-to-end Transport Layer Security (TLS) termination, previously known as Secure Sockets Layer (SSL)
termination.
Infrastructure
The Application Gateway infrastructure includes the virtual network, subnets, network security groups, and user
defined routes.
For more information, see Application Gateway infrastructure configuration.
Front-end IP address
You can configure the application gateway to have a public IP address, a private IP address, or both. A public IP is
required when you host a back end that clients must access over the Internet via an Internet-facing virtual IP
(VIP).
For more information, see Application Gateway front-end IP address configuration.
Listeners
A listener is a logical entity that checks for incoming connection requests by using the port, protocol, host, and
IP address. When you configure the listener, you must enter values for these that match the corresponding
values in the incoming request on the gateway.
For more information, see Application Gateway listener configuration.
HTTP settings
The application gateway routes traffic to the back-end servers by using the configuration that you specify here.
After you create an HTTP setting, you must associate it with one or more request-routing rules.
For more information, see Application Gateway HTTP settings configuration.
Back-end pool
You can point a back-end pool to four types of backend members: a specific virtual machine, a virtual machine
scale set, an IP address/FQDN, or an app service.
After you create a back-end pool, you must associate it with one or more request-routing rules. You must also
configure health probes for each back-end pool on your application gateway. When a request-routing rule
condition is met, the application gateway forwards the traffic to the healthy servers (as determined by the health
probes) in the corresponding back-end pool.
Health probes
An application gateway monitors the health of all resources in its back end by default. But we strongly
recommend that you create a custom probe for each back-end HTTP setting to get greater control over health
monitoring. To learn how to configure a custom probe, see Custom health probe settings.
NOTE
After you create a custom health probe, you need to associate it to a back-end HTTP setting. A custom probe won't
monitor the health of the back-end pool unless the corresponding HTTP setting is explicitly associated with a listener
using a rule.
Next steps
Now that you know about Application Gateway components, you can:
Create an application gateway in the Azure portal
Create an application gateway using PowerShell
Create an application gateway using the Azure CLI
Application Gateway infrastructure configuration
3/5/2021 • 5 minutes to read • Edit Online
The application gateway infrastructure includes the virtual network, subnets, network security groups, and user
defined routes.
NOTE
Virtual network service endpoint policies are currently not supported in an Application Gateway subnet.
v1
For the v1 SKU, user-defined routes (UDRs) are supported on the Application Gateway subnet, as long as
they don't alter end-to-end request/response communication. For example, you can set up a UDR in the
Application Gateway subnet to point to a firewall appliance for packet inspection. But you must make
sure that the packet can reach its intended destination after inspection. Failure to do so might result in
incorrect health-probe or traffic-routing behavior. This includes learned routes or default 0.0.0.0/0 routes
that are propagated by Azure ExpressRoute or VPN gateways in the virtual network. Any scenario in
which 0.0.0.0/0 needs to be redirected on-premises (forced tunneling) isn't supported for v1.
v2
For the v2 SKU, there are supported and unsupported scenarios:
v2 suppor ted scenarios
WARNING
An incorrect configuration of the route table could result in asymmetrical routing in Application Gateway v2.
Ensure that all management/control plane traffic is sent directly to the Internet and not through a virtual
appliance. Logging and metrics could also be affected.
Scenario 1 : UDR to disable Border Gateway Protocol (BGP) Route Propagation to the Application
Gateway subnet
Sometimes the default gateway route (0.0.0.0/0) is advertised via the ExpressRoute or VPN gateways
associated with the Application Gateway virtual network. This breaks management plane traffic, which
requires a direct path to the Internet. In such scenarios, a UDR can be used to disable BGP route
propagation.
To disable BGP route propagation, use the following steps:
1. Create a Route Table resource in Azure.
2. Disable the Vir tual network gateway route propagation parameter.
3. Associate the Route Table to the appropriate subnet.
Enabling the UDR for this scenario shouldn't break any existing setups.
Scenario 2 : UDR to direct 0.0.0.0/0 to the Internet
You can create a UDR to send 0.0.0.0/0 traffic directly to the Internet.
Scenario 3 : UDR for Azure Kubernetes Service with kubenet
If you're using kubenet with Azure Kubernetes Service (AKS) and Application Gateway Ingress Controller
(AGIC), you'll need a route table to allow traffic sent to the pods from Application Gateway to be routed to
the correct node. This won't be necessary if you use Azure CNI.
To use the route table to allow kubenet to work, follow the steps below:
1. Go to the resource group created by AKS (the name of the resource group should begin with "MC_")
2. Find the route table created by AKS in that resource group. The route table should be populated with
the following information:
Address prefix should be the IP range of the pods you want to reach in AKS.
Next hop type should be Virtual Appliance.
Next hop address should be the IP address of the node hosting the pods.
3. Associate this route table to the Application Gateway subnet.
v2 unsuppor ted scenarios
Scenario 1 : UDR for Virtual Appliances
Any scenario where 0.0.0.0/0 needs to be redirected through any virtual appliance, a hub/spoke virtual
network, or on-premise (forced tunneling) isn't supported for V2.
Next steps
Learn about front-end IP address configuration.
Application Gateway front-end IP address
configuration
3/10/2021 • 2 minutes to read • Edit Online
You can configure the application gateway to have a public IP address, a private IP address, or both. A public IP
address is required when you host a back end that clients must access over the Internet via an Internet-facing
virtual IP (VIP).
Next steps
Learn about listener configuration
Application Gateway listener configuration
3/5/2021 • 4 minutes to read • Edit Online
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
A listener is a logical entity that checks for incoming connection requests by using the port, protocol, host, and
IP address. When you configure the listener, you must enter values for these that match the corresponding
values in the incoming request on the gateway.
When you create an application gateway by using the Azure portal, you also create a default listener by
choosing the protocol and port for the listener. You can choose whether to enable HTTP2 support on the listener.
After you create the application gateway, you can edit the settings of that default listener
(appGatewayHttpListener) or create new listeners.
Listener type
When you create a new listener, you choose between basic and multi-site.
If you want all of your requests (for any domain) to be accepted and forwarded to backend pools, choose
basic. Learn how to create an application gateway with a basic listener.
If you want to forward requests to different backend pools based on the host header or host names,
choose multi-site listener, where you must also specify a host name that matches with the incoming
request. This is because Application Gateway relies on HTTP 1.1 host headers to host more than one
website on the same public IP address and port. To learn more, see hosting multiple sites using
Application Gateway.
Order of processing listeners
For the v1 SKU, requests are matched according to the order of the rules and the type of listener. If a rule with
basic listener comes first in the order, it's processed first and will accept any request for that port and IP
combination. To avoid this, configure the rules with multi-site listeners first and push the rule with the basic
listener to the last in the list.
For the v2 SKU, multi-site listeners are processed before basic listeners.
Front-end IP address
Choose the front-end IP address that you plan to associate with this listener. The listener will listen to incoming
requests on this IP.
Front-end port
Choose the front-end port. Select an existing port or create a new one. Choose any value from the allowed
range of ports. You can use not only well-known ports, such as 80 and 443, but any allowed custom port that's
suitable. A port can be used for public-facing listeners or private-facing listeners.
Protocol
Choose HTTP or HTTPS:
If you choose HTTP, the traffic between the client and the application gateway is unencrypted.
Choose HTTPS if you want TLS termination or end-to-end TLS encryption. The traffic between the client
and the application gateway is encrypted. And the TLS connection terminates at the application gateway.
If you want end-to-end TLS encryption, you must choose HTTPS and configure the back-end HTTP
setting. This ensures that traffic is re-encrypted when it travels from the application gateway to the back
end.
To configure TLS termination and end-to-end TLS encryption, you must add a certificate to the listener to enable
the application gateway to derive a symmetric key. This is dictated by the TLS protocol specification. The
symmetric key is used to encrypt and decrypt the traffic that's sent to the gateway. The gateway certificate must
be in Personal Information Exchange (PFX) format. This format lets you export the private key that the gateway
uses to encrypt and decrypt traffic.
Supported certificates
See Overview of TLS termination and end to end TLS with Application Gateway
$gw.EnableHttp2 = $true
WebSocket support
WebSocket support is enabled by default. There's no user-configurable setting to enable or disable it. You can
use WebSockets with both HTTP and HTTPS listeners.
TLS policy
You can centralize TLS/SSL certificate management and reduce encryption-decryption overhead for a back-end
server farm. Centralized TLS handling also lets you specify a central TLS policy that's suited to your security
requirements. You can choose default, predefined, or custom TLS policy.
You configure TLS policy to control TLS protocol versions. You can configure an application gateway to use a
minimum protocol version for TLS handshakes from TLS1.0, TLS1.1, and TLS1.2. By default, SSL 2.0 and 3.0 are
disabled and aren't configurable. For more information, see Application Gateway TLS policy overview.
After you create a listener, you associate it with a request-routing rule. That rule determines how requests that
are received on the listener are routed to the back end.
Next steps
Learn about request routing rules.
Application Gateway request routing rules
3/5/2021 • 4 minutes to read • Edit Online
When you create an application gateway using the Azure portal, you create a default rule (rule1). This rule binds
the default listener (appGatewayHttpListener) with the default back-end pool (appGatewayBackendPool) and the
default back-end HTTP settings (appGatewayBackendHttpSettings). After you create the gateway, you can edit
the settings of the default rule or create new rules.
Rule type
When you create a rule, you choose between basic and path-based.
Choose basic if you want to forward all requests on the associated listener (for example, blog.contoso.com/*)
to a single back-end pool.
Choose path-based if you want to route requests from specific URL paths to specific back-end pools. The
path pattern is applied only to the path of the URL, not to its query parameters.
Order of processing rules
For the v1 and v2 SKU, pattern matching of incoming requests is processed in the order that the paths are listed
in the URL path map of the path-based rule. If a request matches the pattern in two or more paths in the path
map, the path that's listed first is matched. And the request is forwarded to the back end that's associated with
that path.
Associated listener
Associate a listener to the rule so that the request-routing rule that's associated with the listener is evaluated to
determine the back-end pool to route the request to.
Next steps
Learn about HTTP settings
Application Gateway HTTP settings configuration
11/2/2020 • 5 minutes to read • Edit Online
The application gateway routes traffic to the back-end servers by using the configuration that you specify here.
After you create an HTTP setting, you must associate it with one or more request-routing rules.
Cookie-based affinity
Azure Application Gateway uses gateway-managed cookies for maintaining user sessions. When a user sends
the first request to Application Gateway, it sets an affinity cookie in the response with a hash value which
contains the session details, so that the subsequent requests carrying the affinity cookie will be routed to the
same backend server for maintaining stickiness.
This feature is useful when you want to keep a user session on the same server and when session state is saved
locally on the server for a user session. If the application can't handle cookie-based affinity, you can't use this
feature. To use it, make sure that the clients support cookies.
The Chromium browser v80 update brought a mandate where HTTP cookies without SameSite attribute has to
be treated as SameSite=Lax. In the case of CORS (Cross-Origin Resource Sharing) requests, if the cookie has to
be sent in a third-party context, it has to use SameSite=None; Secure attributes and it should be sent over
HTTPS only. Otherwise, in a HTTP only scenario, the browser doesn't send the cookies in the third-party context.
The goal of this update from Chrome is to enhance security and to avoid Cross-Site Request Forgery (CSRF)
attacks.
To support this change, starting February 17 2020, Application Gateway (all the SKU types) will inject another
cookie called ApplicationGatewayAffinityCORS in addition to the existing ApplicationGatewayAffinity cookie. The
ApplicationGatewayAffinityCORS cookie has two more attributes added to it ("SameSite=None; Secure") so that
sticky session are maintained even for cross-origin requests.
Note that the default affinity cookie name is ApplicationGatewayAffinity and you can change it. In case you're
using a custom affinity cookie name, an additional cookie is added with CORS as suffix. For example,
CustomCookieNameCORS .
NOTE
If the attribute SameSite=None is set, it is mandatory that the cookie also contains the Secure flag, and must be sent over
HTTPS. If session affinity is required over CORS, you must migrate your workload to HTTPS. Please refer to TLS offload and
End-to-End TLS documentation for Application Gateway here – Overview, Configure an application gateway with TLS
termination using the Azure portal, Configure end-to-end TLS by using Application Gateway with the portal.
Connection draining
Connection draining helps you gracefully remove back-end pool members during planned service updates. You
can apply this setting to all members of a back-end pool by enabling connection draining on the HTTP setting. It
ensures that all deregistering instances of a back-end pool continue to maintain existing connections and serve
on-going requests for a configurable timeout and don't receive any new requests or connections. The only
exception to this are requests bound for deregistering instances because of gateway-managed session affinity
and will continue to be forwarded to the deregistering instances. Connection draining applies to back-end
instances that are explicitly removed from the back-end pool.
Protocol
Application Gateway supports both HTTP and HTTPS for routing requests to the back-end servers. If you choose
HTTP, traffic to the back-end servers is unencrypted. If unencrypted communication isn't acceptable, choose
HTTPS.
This setting combined with HTTPS in the listener supports end-to-end TLS. This allows you to securely transmit
sensitive data encrypted to the back end. Each back-end server in the back-end pool that has end-to-end TLS
enabled must be configured with a certificate to allow secure communication.
Port
This setting specifies the port where the back-end servers listen to traffic from the application gateway. You can
configure ports ranging from 1 to 65535.
Request timeout
This setting is the number of seconds that the application gateway waits to receive a response from the back-
end server.
NOTE
The custom probe doesn't monitor the health of the back-end pool unless the corresponding HTTP setting is explicitly
associated with a listener.
NOTE
This setting is not required for App Service Environment, which is a dedicated deployment.
Next steps
Learn about the back-end pool
Application Gateway high traffic support
3/5/2021 • 10 minutes to read • Edit Online
NOTE
This article describes a few suggested guidelines to help you set up your Application Gateway to handle extra traffic for
any high traffic volume that may occur. The alert thresholds are purely suggestions and generic in nature. Users can
determine alert thresholds based on their workload and utilization expectations.
You can use Application Gateway with Web Application Firewall (WAF) for a scalable and secure way to manage
traffic to your web applications.
It is important that you scale your Application Gateway according to your traffic and with a bit of a buffer so that
you are prepared for any traffic surges or spikes and minimizing the impact that it may have in your QoS. The
following suggestions help you set up Application Gateway with WAF to handle extra traffic.
Please check the metrics documentation for the complete list of metrics offered by Application Gateway. See
visualize metrics in the Azure portal and the Azure monitor documentation on how to set alerts for metrics.
Use the v2 SKU over v1 for its autoscaling capabilities and performance benefits
The v2 SKU offers autoscaling to ensure that your Application Gateway can scale up as traffic increases. It also
offers other significant performance benefits, such as 5x better TLS offload performance, quicker deployment
and update times, zone redundancy, and more when compared to v1. For more information, see our v2
documentation and see our v1 to v2 migration documentation to learn how to migrate your existing v1 SKU
gateways to v2 SKU.
Set your minimum instance count based on your average Compute Unit usage
For Application Gateway v2 SKU, autoscaling takes six to seven minutes to scale out and provision additional set
of instances ready to take traffic. Until then, if there are short spikes in traffic, your existing gateway instances
might get under stress and this may cause unexpected latency or loss of traffic.
It is recommended that you set your minimum instance count to an optimal level. For example, if you require 50
instances to handle the traffic at peak load, then setting the minimum 25 to 30 is a good idea rather than at <10
so that even when there are short bursts of traffic, Application Gateway would be able to handle it and give
enough time for autoscaling to respond and take effect.
Check your Compute Unit metric for the past one month. Compute unit metric is a representation of your
gateway's CPU utilization and based on your peak usage divided by 10, you can set the minimum number of
instances required. Note that 1 application gateway instance can handle a minimum of 10 compute units
Manual scaling for Application Gateway v2 SKU (Standard_v2/WAF_v2)
Set your instance count based on your peak Compute Unit usage
Unlike autoscaling, in manual scaling, you must manually set the number of instances of your application
gateway based on the traffic requirements. It is recommended that you set your instance count according to
your peak usage and with a 10% to 20% additional buffer to account for any traffic spikes. For example, if your
traffic requires 50 instances at peak, provision 55 to 60 instances to handle unexpected traffic spikes that may
occur.
Check your Compute Unit metric for the past one month. Compute unit metric is a representation of your
gateway's CPU utilization and based on your peak usage divided by 10, you can set the number of instances
required, since 1 application gateway instance can handle a minimum of 10 compute units
NOTE
You can set the alert to occur at a lower or higher CU utilization percentage depending on how sensitive you want to be
to potential traffic spikes.
Set up WAF with geo filtering and bot protection to stop attacks
If you want an extra layer of security in front of your application, use the Application Gateway WAF_v2 SKU for
WAF capabilities. You can configure the v2 SKU to only allow access to your applications from a given
country/region or countries/regions. You set up a WAF custom rule to explicitly allow or block traffic based on
the geo location. For more information, see geo filtering custom rules and how to configure custom rules on
Application Gateway WAF_v2 SKU through PowerShell.
Enable bot protection to block known bad bots. This should reduce the amount of traffic getting to your
application. For more information, see bot protection with set up instructions.
Application Gateway is available under a Standard_v2 SKU. Web Application Firewall (WAF) is available under a
WAF_v2 SKU. The v2 SKU offers performance enhancements and adds support for critical new features like
autoscaling, zone redundancy, and support for static VIPs. Existing features under the Standard and WAF SKU
continue to be supported in the new v2 SKU, with a few exceptions listed in comparison section.
The new v2 SKU includes the following enhancements:
Autoscaling : Application Gateway or WAF deployments under the autoscaling SKU can scale out or in
based on changing traffic load patterns. Autoscaling also removes the requirement to choose a
deployment size or instance count during provisioning. This SKU offers true elasticity. In the Standard_v2
and WAF_v2 SKU, Application Gateway can operate both in fixed capacity (autoscaling disabled) and in
autoscaling enabled mode. Fixed capacity mode is useful for scenarios with consistent and predictable
workloads. Autoscaling mode is beneficial in applications that see variance in application traffic.
Zone redundancy : An Application Gateway or WAF deployment can span multiple Availability Zones,
removing the need to provision separate Application Gateway instances in each zone with a Traffic
Manager. You can choose a single zone or multiple zones where Application Gateway instances are
deployed, which makes it more resilient to zone failure. The backend pool for applications can be
similarly distributed across availability zones.
Zone redundancy is available only where Azure Zones are available. In other regions, all other features
are supported. For more information, see Regions and Availability Zones in Azure
Static VIP : Application Gateway v2 SKU supports the static VIP type exclusively. This ensures that the VIP
associated with the application gateway doesn't change for the lifecycle of the deployment, even after a
restart. There isn't a static VIP in v1, so you must use the application gateway URL instead of the IP
address for domain name routing to App Services via the application gateway.
Header Rewrite : Application Gateway allows you to add, remove, or update HTTP request and response
headers with v2 SKU. For more information, see Rewrite HTTP headers with Application Gateway
Key Vault Integration : Application Gateway v2 supports integration with Key Vault for server
certificates that are attached to HTTPS enabled listeners. For more information, see TLS termination with
Key Vault certificates.
Azure Kubernetes Ser vice Ingress Controller : The Application Gateway v2 Ingress Controller allows
the Azure Application Gateway to be used as the ingress for an Azure Kubernetes Service (AKS) known as
AKS Cluster. For more information, see What is Application Gateway Ingress Controller?.
Performance enhancements : The v2 SKU offers up to 5X better TLS offload performance as compared
to the Standard/WAF SKU.
Faster deployment and update time The v2 SKU provides faster deployment and update time as
compared to Standard/WAF SKU. This also includes WAF configuration changes.
Supported regions
The Standard_v2 and WAF_v2 SKU is available in the following regions: North Central US, South Central US,
West US, West US 2, East US, East US 2, Central US, North Europe, West Europe, Southeast Asia, France Central,
UK West, Japan East, Japan West, Australia East, Australia Southeast, Brazil South, Canada Central, Canada East,
East Asia, Korea Central, Korea South, UK South, Central India, West India, South India.
Pricing
With the v2 SKU, the pricing model is driven by consumption and is no longer attached to instance counts or
sizes. The v2 SKU pricing has two components:
Fixed price - This is hourly (or partial hour) price to provision a Standard_v2 or WAF_v2 Gateway. Please
note that 0 additional minimum instances still ensures high availability of the service which is always
included with fixed price.
Capacity Unit price - This is a consumption-based cost that is charged in addition to the fixed cost.
Capacity unit charge is also computed hourly or partial hourly. There are three dimensions to capacity unit -
compute unit, persistent connections, and throughput. Compute unit is a measure of processor capacity
consumed. Factors affecting compute unit are TLS connections/sec, URL Rewrite computations, and WAF rule
processing. Persistent connection is a measure of established TCP connections to the application gateway in a
given billing interval. Throughput is average Megabits/sec processed by the system in a given billing interval.
The billing is done at a Capacity Unit level for anything above the reserved instance count.
Each capacity unit is composed of at most: 1 compute unit, 2500 persistent connections, and 2.22-Mbps
throughput.
To learn more, see Understanding pricing.
Scaling Application Gateway and WAF v2
Application Gateway and WAF can be configured to scale in two modes:
Autoscaling - With autoscaling enabled, the Application Gateway and WAF v2 SKUs scale up or down based
on application traffic requirements. This mode offers better elasticity to your application and eliminates the
need to guess the application gateway size or instance count. This mode also allows you to save cost by not
requiring the gateway to run at peak provisioned capacity for anticipated maximum traffic load. You must
specify a minimum and optionally maximum instance count. Minimum capacity ensures that Application
Gateway and WAF v2 don't fall below the minimum instance count specified, even in the absence of traffic.
Each instance is roughly equivalent to 10 additional reserved Capacity Units. Zero signifies no reserved
capacity and is purely autoscaling in nature. You can also optionally specify a maximum instance count, which
ensures that the Application Gateway doesn't scale beyond the specified number of instances. You will only
be billed for the amount of traffic served by the Gateway. The instance counts can range from 0 to 125. The
default value for maximum instance count is 20 if not specified.
Manual - You can alternatively choose Manual mode where the gateway won't autoscale. In this mode, if
there is more traffic than what Application Gateway or WAF can handle, it could result in traffic loss. With
manual mode, specifying instance count is mandatory. Instance count can vary from 1 to 125 instances.
F EAT URE V1 SK U V2 SK U
Autoscaling ✓
Zone redundancy ✓
Static VIP ✓
URL-based routing ✓ ✓
Multiple-site hosting ✓ ✓
Traffic redirection ✓ ✓
Session affinity ✓ ✓
WebSocket support ✓ ✓
HTTP/2 support ✓ ✓
Connection draining ✓ ✓
NOTE
The autoscaling v2 SKU now supports default health probes to automatically monitor the health of all resources in its
back-end pool and highlight those backend members that are considered unhealthy. The default health probe is
automatically configured for backends that don't have any custom probe configuration. To learn more, see health probes
in application gateway.
User-Defined Route (UDR) on Application Gateway subnet Supported (specific scenarios). In preview.
For more information about supported scenarios, see
Application Gateway configuration overview.
DIF F EREN C E DETA IL S
NSG for Inbound port range - 65200 to 65535 for Standard_v2 SKU
- 65503 to 65534 for Standard SKU.
For more information, see the FAQ.
ILB only mode This is currently not supported. Public and ILB mode
together is supported.
Migrate from v1 to v2
An Azure PowerShell script is available in the PowerShell gallery to help you migrate from your v1 Application
Gateway/WAF to the v2 Autoscaling SKU. This script helps you copy the configuration from your v1 gateway.
Traffic migration is still your responsibility. For more information, see Migrate Azure Application Gateway from
v1 to v2.
Next steps
Quickstart: Direct web traffic with Azure Application Gateway - Azure portal
Create an autoscaling, zone redundant application gateway with a reserved virtual IP address using Azure
PowerShell
Learn more about Application Gateway.
Learn more about Azure Firewall.
Application Gateway multiple site hosting
11/2/2020 • 6 minutes to read • Edit Online
Multiple site hosting enables you to configure more than one web application on the same port of an
application gateway. It allows you to configure a more efficient topology for your deployments by adding up to
100+ websites to one application gateway. Each website can be directed to its own backend pool. For example,
three domains, contoso.com, fabrikam.com, and adatum.com, point to the IP address of the application gateway.
You'd create three multi-site listeners and configure each listener for the respective port and protocol setting.
You can also define wildcard host names in a multi-site listener and up to 5 host names per listener. To learn
more, see wildcard host names in listener.
IMPORTANT
Rules are processed in the order they are listed in the portal for the v1 SKU. For the v2 SKU, exact matches have higher
precedence. It is highly recommended to configure multi-site listeners first prior to configuring a basic listener. This will
ensure that traffic gets routed to the right back end. If a basic listener is listed first and matches an incoming request, it
gets processed by that listener.
Requests for http://contoso.com are routed to ContosoServerPool, and http://fabrikam.com are routed to
FabrikamServerPool.
Similarly, you can host multiple subdomains of the same parent domain on the same application gateway
deployment. For example, you can host http://blog.contoso.com and http://app.contoso.com on a single
application gateway deployment.
NOTE
This feature is currently available only through Azure PowerShell and Azure CLI. Portal support is coming soon. Please
note that since portal support is not fully available, if you are using only the HostNames parameter, the listener will
appear as a Basic listener in the portal and the Host name column of the listener list view will not show the host names
that are configured. For any changes to a wildcard listener, make sure you use Azure PowerShell or CLI until it's supported
in the portal.
In Azure PowerShell, you must use -HostNames instead of -HostName . With HostNames, you can mention up to
5 host names as comma-separated values and use wildcard characters. For example,
-HostNames "*.contoso.com,*.fabrikam.com"
In Azure CLI, you must use --host-names instead of --host-name . With host-names, you can mention up to 5
host names as comma-separated values and use wildcard characters. For example,
--host-names "*.contoso.com,*.fabrikam.com"
Conditions for using wildcard characters and multiple host names in a listener:
You can only mention up to 5 host names in a single listener
Asterisk * can be mentioned only once in a component of a domain style name or host name. For example,
component1*.component2*.component3. (*.contoso-*.com) is valid.
There can only be up to two asterisks * in a host name. For example, *.contoso.* is valid and
*.contoso.*.*.com is invalid.
There can only be a maximum of 4 wildcard characters in a host name. For example, ????.contoso.com ,
w??.contoso*.edu.* are valid, but ????.contoso.* is invalid.
Using asterisk * and question mark ? together in a component of a host name ( *? or ?* or ** ) is
invalid. For example, *?.contoso.com and **.contoso.com are invalid.
Considerations and limitations of using wildcard or multiple host names in a listener:
SSL termination and End-to-End SSL requires you to configure the protocol as HTTPS and upload a
certificate to be used in the listener configuration. If it is a multi-site listener, you can input the host name as
well, usually this is the CN of the SSL certificate. When you are specifying multiple host names in the listener
or use wildcard characters, you must consider the following:
If it is a wildcard hostname like *.contoso.com, you must upload a wildcard certificate with CN like
*.contoso.com
If multiple host names are mentioned in the same listener, you must upload a SAN certificate (Subject
Alternative Names) with the CNs matching the host names mentioned.
You cannot use a regular expression to mention the host name. You can only use wildcard characters like
asterisk (*) and question mark (?) to form the host name pattern.
For backend health check, you cannot associate multiple custom probes per HTTP settings. Instead, you can
probe one of the websites at the backend or use “127.0.0.1” to probe the localhost of the backend server.
However, when you are using wildcard or multiple host names in a listener, the requests for all the specified
domain patterns will be routed to the backend pool depending on the rule type (basic or path-based).
The properties “hostname" takes one string as input, where you can mention only one non-wildcard domain
name and “hostnames” takes an array of strings as input, where you can mention up to 5 wildcard domain
names. But both the properties cannot be used at once.
You cannot create a redirection rule with a target listener which uses wildcard or multiple host names.
See create multi-site using Azure PowerShell or using Azure CLI for the step-by-step guide on how to configure
wildcard host names in a multi-site listener.
Next steps
Learn how to configure multiple site hosting in Application Gateway
Using Azure portal
Using Azure PowerShell
Using Azure CLI
You can visit Resource Manager template using multiple site hosting for an end to end template-based
deployment.
URL Path Based Routing overview
11/2/2020 • 2 minutes to read • Edit Online
URL Path Based Routing allows you to route traffic to back-end server pools based on URL Paths of the request.
One of the scenarios is to route requests for different content types to different backend server pools.
In the following example, Application Gateway is serving traffic for contoso.com from three back-end server
pools for example: VideoServerPool, ImageServerPool, and DefaultServerPool.
IMPORTANT
For the v1 SKU, rules are processed in the order they are listed in the portal. If a basic listener is listed first and matches
an incoming request, it gets processed by that listener. For the v2 SKU, exact matches have higher precedence. However, it
is highly recommended to configure multi-site listeners first prior to configuring a basic listener. This ensures that traffic
gets routed to the right back end.
PathPattern
PathPattern is a list of path patterns to match. Each must start with / and the only place a "*" is allowed is at the
end following a "/." The string fed to the path matcher does not include any text after the first ? or #, and those
chars are not allowed here. Otherwise, any characters allowed in a URL are allowed in PathPattern.
The supported patterns depend on whether you deploy Application Gateway v1 or v2:
v1
Path rules are case insensitive.
/images/* yes
/images* yes
/images/*.jpg no
/*.jpg no
/Repos/*/Comments/* no
/CurrentUser/Comments/* yes
v2
Path rules are case insensitive.
/images/* yes
/images* yes
/images/*.jpg no
/*.jpg no
/Repos/*/Comments/* no
/CurrentUser/Comments/* yes
You can check out a Resource Manager template using URL-based routing for more information.
PathBasedRouting rule
RequestRoutingRule of type PathBasedRouting is used to bind a listener to a urlPathMap. All requests that are
received for this listener are routed based on policy specified in urlPathMap. Snippet of PathBasedRouting rule:
"requestRoutingRules": [
{
"name": "{ruleName}",
"id":
"/subscriptions/{subscriptionId}/../microsoft.network/applicationGateways/{gatewayName}/requestRoutingRules/
{ruleName}",
"properties": {
"ruleType": "PathBasedRouting",
"httpListener": {
"id":
"/subscriptions/{subscriptionId}/../microsoft.network/applicationGateways/{gatewayName}/httpListeners/<liste
nerName>"
},
"urlPathMap": {
"id":
"/subscriptions/{subscriptionId}/../microsoft.network/applicationGateways/{gatewayName}/urlPathMaps/{urlpath
MapName}"
}
}
}
]
Next steps
After learning about URL-based content routing, go to create an application gateway using URL-based routing
to create an application gateway with URL routing rules.
Application Gateway redirect overview
11/2/2020 • 2 minutes to read • Edit Online
You can use application gateway to redirect traffic. It has a generic redirection mechanism which allows for
redirecting traffic received at one listener to another listener or to an external site. This simplifies application
configuration, optimizes the resource usage, and supports new redirection scenarios including global and path-
based redirection.
A common redirection scenario for many web applications is to support automatic HTTP to HTTPS redirection to
ensure all communication between application and its users occurs over an encrypted path. In the past,
customers have used techniques such as creating a dedicated backend pool whose sole purpose is to redirect
requests it receives on HTTP to HTTPS. With redirection support in Application Gateway, you can accomplish this
simply by adding a new redirect configuration to a routing rule, and specifying another listener with HTTPS
protocol as the target listener.
The following types of redirection are supported:
301 Permanent Redirect
302 Found
303 See Other
307 Temporary Redirect
Application Gateway redirection support offers the following capabilities:
Global redirection
Redirects from one listener to another listener on the gateway. This enables HTTP to HTTPS redirection on
a site.
Path-based redirection
This type of redirection enables HTTP to HTTPS redirection only on a specific site area, for example a
shopping cart area denoted by /cart/*.
Redirect to external site
With this change, customers need to create a new redirect configuration object, which specifies the target
listener or external site to which redirection is desired. The configuration element also supports options to
enable appending the URI path and query string to the redirected URL. You can also choose the type of
redirection. Once created, this redirect configuration is attached to the source listener via a new rule. When
using a basic rule, the redirect configuration is associated with a source listener and is a global redirect. When a
path-based rule is used, the redirect configuration is defined on the URL path map. So it only applies to the
specific path area of a site.
Next steps
Configure URL redirection on an application gateway
Rewrite HTTP headers and URL with Application
Gateway
4/2/2021 • 15 minutes to read • Edit Online
Application Gateway allows you to rewrite selected content of requests and responses. With this feature, you can
translate URLs, query string parameters as well as modify request and response headers. It also allows you to
add conditions to ensure that the URL or the specified headers are rewritten only when certain conditions are
met. These conditions are based on the request and response information.
NOTE
HTTP header and URL rewrite features are only available for the Application Gateway v2 SKU
Rewrite actions
You use rewrite actions to specify the URL, request headers or response headers that you want to rewrite and
the new value to which you intend to rewrite them to. The value of a URL or a new or existing header can be set
to these types of values:
Text
Request header. To specify a request header, you need to use the syntax {http_req_headerName}
Response header. To specify a response header, you need to use the syntax {http_resp_headerName}
Server variable. To specify a server variable, you need to use the syntax {var_serverVariable}. See the list of
supported server variables
A combination of text, a request header, a response header, and a server variable.
Rewrite Conditions
You can use rewrite conditions, an optional configuration, to evaluate the content of HTTP(S) requests and
responses and perform a rewrite only when one or more conditions are met. The application gateway uses these
types of variables to evaluate the content of requests and responses:
HTTP headers in the request
HTTP headers in the response
Application Gateway server variables
You can use a condition to evaluate whether a specified variable is present, whether a specified variable matches
a specific value, or whether a specified variable matches a specific pattern.
Pattern Matching
Application Gateway uses regular expressions for pattern matching in the condition. You can use the Perl
Compatible Regular Expressions (PCRE) library to set up regular expression pattern matching in the conditions.
To learn about regular expression syntax, see the Perl regular expressions main page.
Capturing
To capture a substring for later use, put parentheses around the subpattern that matches it in the condition
regex definition. The first pair of parentheses stores its substring in 1, the second pair in 2, and so on. You may
use as many parentheses as you like; Perl just keeps defining more numbered variables for you to represent
these captured strings. Some examples from ref:
/(\d)(\d)/ # Match two digits, capturing them into groups 1 and 2
/(\d+)/ # Match one or more digits, capturing them all into group 1
/(\d)+/ # Match a digit one or more times, capturing the last into group 1
Once captured, you can reference them in the action set using the following format:
For a request header capture, you must use {http_req_headerName_groupNumber}. For example,
{http_req_User-Agent_1} or {http_req_User-Agent_2}
For a response header capture, you must use {http_resp_headerName_groupNumber}. For example,
{http_resp_Location_1} or {http_resp_Location_2}
For a server variable, you must use {var_serverVariableName_groupNumber}. For example, {var_uri_path_1}
or {var_uri_path_2}
If you want to use the whole value, you should not mention the number. Simply use the format
{http_req_headerName}, etc. without the groupNumber.
Server variables
Application Gateway uses server variables to store useful information about the server, the connection with the
client, and the current request on the connection. Examples of information stored include the client’s IP address
and the web browser type. Server variables change dynamically, for example, when a new page loads or when a
form is posted. You can use these variables to evaluate rewrite conditions and rewrite headers. In order to use
the value of server variables to rewrite headers, you will need to specify these variables in the syntax
{var_serverVariableName}
Application gateway supports the following server variables:
host In this order of precedence: the host name from the request
line, the host name from the Host request header field, or
the server name matching a request. Example: in the request
http://contoso.com:8080/article.aspx?
id=123&title=fabrikam
, host value will be is contoso.com
http_method The method used to make the URL request. For example,
GET or POST.
query_string The list of variable/value pairs that follows the "?" in the
requested URL. Example: in the request
http://contoso.com:8080/article.aspx?
id=123&title=fabrikam
, query_string value will be id=123&title=fabrikam
received_bytes The length of the request (including the request line, header,
and request body).
uri_path Identifies the specific resource in the host that the web client
wants to access. This is the part of the request URI without
the arguments. Example: in the request
http://contoso.com:8080/article.aspx?
id=123&title=fabrikam
, uri_path value will be /article.aspx
Rewrite configuration
To configure a rewrite rule, you need to create a rewrite rule set and add the rewrite rule configuration in it.
A rewrite rule set contains:
Request routing rule association: The rewrite configuration is associated to the source listener via the
routing rule. When you use a basic routing rule, the rewrite configuration is associated with a source
listener and is a global header rewrite. When you use a path-based routing rule, the rewrite configuration
is defined on the URL path map. In that case, it applies only to the specific path area of a site. You can
create multiple rewrite sets and apply each rewrite set to multiple listeners. But you can apply only one
rewrite set to a specific listener.
Rewrite Condition : It is an optional configuration. Rewrite conditions evaluate the content of the
HTTP(S) requests and responses. The rewrite action will occur if the HTTP(S) request or response matches
the rewrite condition. If you associate more than one condition with an action, the action occurs only
when all the conditions are met. In other words, the operation is a logical AND operation.
Rewrite type : There are 3 types of rewrites available:
Rewriting request headers
Rewriting response headers.
Rewriting URL: URL rewrite type has 3 components
URL path : The value to which the path is to be rewritten to.
URL Quer y String : The value to which the query string is to be rewritten to.
Re-evaluate path map : Used to determine whether the URL path map is to be re-evaluated
or not. If kept unchecked, the original URL path will be used to match the path-pattern in the
URL path map. If set to true, the URL path map will be re-evaluated to check the match with the
rewritten path. Enabling this switch helps in routing the request to a different backend pool
post rewrite.
Common scenarios for header rewrite
Remove port information from the X-Forwarded-For header
Application Gateway inserts an X-Forwarded-For header into all requests before it forwards the requests to the
backend. This header is a comma-separated list of IP ports. There might be scenarios in which the back-end
servers only need the headers to contain IP addresses. You can use header rewrite to remove the port
information from the X-Forwarded-For header. One way to do this is to set the header to the
add_x_forwarded_for_proxy server variable. Alternatively, you can also use the variable client_ip:
Modify a redirection URL
When a back-end application sends a redirection response, you might want to redirect the client to a different
URL than the one specified by the back-end application. For example, you might want to do this when an app
service is hosted behind an application gateway and requires the client to do a redirection to its relative path.
(For example, a redirect from contoso.azurewebsites.net/path1 to contoso.azurewebsites.net/path2.)
Because App Service is a multitenant service, it uses the host header in the request to route the request to the
correct endpoint. App services have a default domain name of *.azurewebsites.net (say
contoso.azurewebsites.net) that's different from the application gateway's domain name (say contoso.com).
Because the original request from the client has the application gateway's domain name (contoso.com) as the
hostname, the application gateway changes the hostname to contoso.azurewebsites.net. It makes this change so
that the app service can route the request to the correct endpoint.
When the app service sends a redirection response, it uses the same hostname in the location header of its
response as the one in the request it receives from the application gateway. So the client will make the request
directly to contoso.azurewebsites.net/path2 instead of going through the application gateway (
contoso.com/path2 ). Bypassing the application gateway isn't desirable.
You can resolve this issue by setting the hostname in the location header to the application gateway's domain
name.
Here are the steps for replacing the hostname:
1. Create a rewrite rule with a condition that evaluates if the location header in the response contains
azurewebsites.net. Enter the pattern (https?):\/\/.*azurewebsites\.net(.*)$ .
2. Perform an action to rewrite the location header so that it has the application gateway's hostname. Do this by
entering {http_resp_Location_1}://contoso.com{http_resp_Location_2} as the header value. Alternatively, you
can also use the server variable host to set the hostname to match the original request.
Implement security HTTP headers to prevent vulnerabilities
You can fix several security vulnerabilities by implementing necessary headers in the application response.
These security headers include X-XSS-Protection, Strict-Transport-Security, and Content-Security-Policy. You can
use Application Gateway to set these headers for all responses.
Now, if the user requests contoso.com/listing?category=any, then it will be matched with the default path since
none of the path patterns in the path map (/listing1, /listing2, /listing3) will match. Since you associated the
above rewrite set with this path, this rewrite set will be evaluated. As the query string will not match the
condition in any of the 3 rewrite rules in this rewrite set, no rewrite action will take place and therefore, the
request will be routed unchanged to the backend associated with the default path (which is GenericList).
If the user requests contoso.com/listing?category=shoes, then again the default path will be matched. However,
in this case the condition in the first rule will match and therefore, the action associated with the condition will
be executed which will rewrite the URL path to /listing1 and re-evaluate the path-map. When the path-map is
re-evaluated, the request will now match the path associated with pattern /listing1 and the request will be
routed to the backend associated with this pattern, which is ShoesListBackendPool
NOTE
This scenario can be extended to any header or cookie value, URL path, query string or server variables based on the
condition defined and essentially enables you to route requests based on those conditions.
Limitations
If a response has more than one header with the same name, then rewriting the value of one of those
headers will result in dropping the other headers in the response. This can usually happen with Set-Cookie
header since you can have more than one Set-Cookie header in a response. One such scenario is when you
are using an app service with an application gateway and have configured cookie-based session affinity on
the application gateway. In this case the response will contain two Set-Cookie headers: one used by the app
service, for example:
Set-Cookie:
ARRAffinity=ba127f1caf6ac822b2347cc18bba0364d699ca1ad44d20e0ec01ea80cda2a735;Path=/;HttpOnly;Domain=sitename.azurewebsites.net
and another for application gateway affinity, for example,
Set-Cookie: ApplicationGatewayAffinity=c1a2bd51lfd396387f96bl9cc3d2c516; Path=/ . Rewriting one of the Set-
Cookie headers in this scenario can result in removing the other Set-Cookie header from the response.
Rewrites are not supported when the application gateway is configured to redirect the requests or to show a
custom error page.
Header names can contain any alphanumeric characters and specific symbols as defined in RFC 7230. We
don't currently support the underscore (_) special character in Header names.
Connection and upgrade headers cannot be rewritten
Next steps
Learn how to rewrite HTTP headers with Application Gateway using Azure portal
Learn how to rewrite URL with Application Gateway using Azure portal
Azure security baseline for Application Gateway
3/26/2021 • 34 minutes to read • Edit Online
This security baseline applies guidance from the Azure Security Benchmark version 1.0 to Application Gateway.
The Azure Security Benchmark provides recommendations on how you can secure your cloud solutions on
Azure. The content is grouped by the security controls defined by the Azure Security Benchmark and the
related guidance applicable to Application Gateway. Controls not applicable to Application Gateway have been
excluded.
To see how Application Gateway completely maps to the Azure Security Benchmark, see the full Application
Gateway security baseline mapping file.
Network Security
For more information, see the Azure Security Benchmark: Network Security.
1.1: Protect Azure resources within virtual networks
Guidance : Ensure that all Virtual Network Azure Application Gateway subnet deployments have a network
security group (NSG) applied with network access controls specific to your application's trusted ports and
sources. While network security groups are supported on Azure Application Gateway, there are some
restrictions and requirements that must be adhered to in order for your NSG and Azure Application Gateway to
function as expected.
Understand restrictions and requirements around using NSGs with Azure Application Gateway
How to create an NSG with a security configuration
Responsibility : Customer
Azure Security Center monitoring : The Azure Security Benchmark is the default policy initiative for Security
Center and is the foundation for Security Center's recommendations. The Azure Policy definitions related to this
control are enabled automatically by Security Center. Alerts related to this control may require an Azure
Defender plan for the related services.
Azure Policy built-in definitions - Microsoft.Network :
NAME VERSIO N
( A ZURE PO RTA L) DESC RIP T IO N EF F EC T ( S) ( GIT HUB)
All Internet traffic should be Azure Security Center has AuditIfNotExists, Disabled 3.0.0-preview
routed via your deployed identified that some of your
Azure Firewall subnets aren't protected
with a next generation
firewall. Protect your
subnets from potential
threats by restricting access
to them with Azure Firewall
or a supported next
generation firewall
NAME VERSIO N
DESC RIP T IO N EF F EC T ( S)
Virtual machines should be This policy audits any Audit, Deny, Disabled 1.0.0
connected to an approved virtual machine connected
virtual network to a virtual network that is
not approved.
Virtual networks should use This policy audits any AuditIfNotExists, Disabled 1.0.0
specified virtual network virtual network if the
gateway default route does not
point to the specified virtual
network gateway.
1.2: Monitor and log the configuration and traffic of virtual networks, subnets, and network interfaces
Guidance : For the network security groups (NSGs) associated with your Azure Application Gateway subnets,
enable NSG flow logs and send logs into a Storage Account for traffic audit. You may also send NSG flow logs to
a Log Analytics Workspace and use Traffic Analytics to provide insights into traffic flow in your Azure cloud.
Some advantages of Traffic Analytics are the ability to visualize network activity and identify hot spots, identify
security threats, understand traffic flow patterns, and pinpoint network misconfigurations.
Note: There are some cases where NSG flow logs associated with your Azure Application Gateway subnets won't
show traffic that has been allowed. If your configuration matches following scenario, you won't see allowed
traffic in your NSG flow logs:
You've deployed Application Gateway v2
You have an NSG on the application gateway subnet
You've enabled NSG flow logs on that NSG
For additional information, see the references below.
How to Enable NSG Flow Logs
How to Enable and use Traffic Analytics
Understand Network Security provided by Azure Security Center
FAQ for diagnostic and Logging for Azure Application Gateway
Responsibility : Customer
Azure Security Center monitoring : The Azure Security Benchmark is the default policy initiative for Security
Center and is the foundation for Security Center's recommendations. The Azure Policy definitions related to this
control are enabled automatically by Security Center. Alerts related to this control may require an Azure
Defender plan for the related services.
Azure Policy built-in definitions - Microsoft.Network :
NAME VERSIO N
( A ZURE PO RTA L) DESC RIP T IO N EF F EC T ( S) ( GIT HUB)
All Internet traffic should be Azure Security Center has AuditIfNotExists, Disabled 3.0.0-preview
routed via your deployed identified that some of your
Azure Firewall subnets aren't protected
with a next generation
firewall. Protect your
subnets from potential
threats by restricting access
to them with Azure Firewall
or a supported next
generation firewall
Data Protection
For more information, see the Azure Security Benchmark: Data Protection.
4.1: Maintain an inventory of sensitive Information
Guidance : Use Tags to assist in tracking Azure resources that store or process sensitive information.
How to create and use Tags
Responsibility : Customer
Azure Security Center monitoring : None
4.2: Isolate systems storing or processing sensitive information
Guidance : Implement separate subscriptions and/or management groups for development, test, and
production. Ensure that all Virtual Network Azure Application Gateway subnet deployments have a network
security group (NSG) applied with network access controls specific to your application's trusted ports and
sources. While network security groups are supported on Azure Application Gateway, there are some
restrictions and requirements that must be adhered to in order for your NSG and Azure Application Gateway to
function as expected.
How to create additional Azure subscriptions
How to create management groups
How to create and use tags
Understand restrictions and requirements around using NSGs with Azure Application Gateway
How to create an NSG with a security configuration
Responsibility : Customer
Azure Security Center monitoring : None
4.3: Monitor and block unauthorized transfer of sensitive information
Guidance : Ensure that all Virtual Network Azure Application Gateway subnet deployments have a network
security group (NSG) applied with network access controls specific to your application's trusted ports and
sources. Restrict outbound traffic to only trusted locations to help mitigate the threat of data exfiltration. While
network security groups are supported on Azure Application Gateway, there are some restrictions and
requirements that must be adhered to in order for your NSG and Azure Application Gateway to function as
expected.
Understand restrictions and requirements around using NSGs with Azure Application Gateway
How to create an NSG with a security configuration
Responsibility : Shared
Azure Security Center monitoring : None
4.4: Encrypt all sensitive information in transit
Guidance : Configure end-to-end encryption with TLS for your Azure Application Gateways.
How to configure end-to-end TLS by using Azure Application Gateway
Responsibility : Shared
Azure Security Center monitoring : None
4.6: Use Role -based access control to control access to resources
Guidance : Use Azure role-based access control (Azure RBAC) to control access to the Azure Application
Gateway control plane (the Azure portal).
How to configure Azure RBAC
Responsibility : Customer
Azure Security Center monitoring : None
4.9: Log and alert on changes to critical Azure resources
Guidance : Use Azure Monitor with the Azure Activity log to create alerts for when changes take place to
production Azure Application Gateway instances as well as other critical or related resources.
How to create alerts for Azure Activity Log events
Responsibility : Customer
Azure Security Center monitoring : None
Vulnerability Management
For more information, see the Azure Security Benchmark: Vulnerability Management.
5.1: Run automated vulnerability scanning tools
Guidance : Currently not available; vulnerability assessment in Azure Security Center is not yet available for
Azure Application Gateway.
Underlying platform scanned and patched by Microsoft. Review security controls available for Azure Application
Gateway to reduce configuration-related vulnerabilities.
Feature coverage (including vulnerability assessment) for Azure PaaS Services
Responsibility : Customer
Azure Security Center monitoring : None
5.4: Compare back-to -back vulnerability scans
Guidance : Not yet available; vulnerability assessment in Azure Security Center is not yet available for Azure
Application Gateway.
Underlying platform scanned and patched by Microsoft. Review security controls available for Azure Application
Gateway to reduce configuration-related vulnerabilities.
Feature coverage (including vulnerability assessment) for Azure PaaS Services
Responsibility : Customer
Azure Security Center monitoring : None
5.5: Use a risk-rating process to prioritize the remediation of discovered vulnerabilities
Guidance : Not yet available; vulnerability assessment in Azure Security Center is not yet available for Azure
Application Gateway.
Underlying platform scanned and patched by Microsoft. Review security controls available for Azure Application
Gateway to reduce configuration-related vulnerabilities.
Feature coverage (including vulnerability assessment) for Azure PaaS Services
Responsibility : Customer
Azure Security Center monitoring : None
Secure Configuration
For more information, see the Azure Security Benchmark: Secure Configuration.
7.1: Establish secure configurations for all Azure resources
Guidance : Define and implement standard security configurations for network settings related to your Azure
Application Gateway deployments. Use Azure Policy aliases in the "Microsoft.Network" namespace to create
custom policies to audit or enforce the network configuration of your Azure Application Gateways, Azure Virtual
Networks, and network security groups. You may also make use of built-in policy definition.
How to view available Azure Policy Aliases
How to configure and manage Azure Policy
Responsibility : Customer
Azure Security Center monitoring : None
7.3: Maintain secure Azure resource configurations
Guidance : Use Azure policy [deny] and [deploy if not exist] to enforce secure settings across your Azure
resources.
How to configure and manage Azure Policy
Understand Azure Policy Effects
Responsibility : Customer
Azure Security Center monitoring : None
7.5: Securely store configuration of Azure resources
Guidance : If using custom Azure policy definitions, use Azure DevOps or Azure Repos to securely store and
manage your code.
How to store code in Azure DevOps
Azure Repos Documentation
Responsibility : Customer
Azure Security Center monitoring : None
7.7: Deploy configuration management tools for Azure resources
Guidance : Use built-in Azure Policy definitions as well as Azure Policy aliases in the "Microsoft.Network"
namespace to create custom policies to alert, audit, and enforce system configurations. Additionally, develop a
process and pipeline for managing policy exceptions.
How to configure and manage Azure Policy
Responsibility : Customer
Azure Security Center monitoring : None
7.9: Implement automated configuration monitoring for Azure resources
Guidance : Use built-in Azure Policy definitions as well as Azure Policy aliases in the "Microsoft.Network"
namespace to create custom policies to alert, audit, and enforce system configurations. Use Azure policy [audit],
[deny], and [deploy if not exist] to automatically enforce configurations for your Azure resources.
How to configure and manage Azure Policy
Responsibility : Customer
Azure Security Center monitoring : None
7.11: Manage Azure secrets securely
Guidance : Use Managed Identities to provide your Azure Application Gateway with an automatically managed
identity in Azure Active Directory (Azure AD). Managed Identities allows you to authenticate to any service that
supports Azure AD authentication, including Key Vault, without any credentials in your code.
Use Azure Key Vault to securely store certificates. Azure Key Vault is a platform-managed secret store that you
can use to safeguard secrets, keys, and SSL certificates. Azure Application Gateway supports integration with
Key Vault for server certificates that are attached to HTTPS-enabled listeners. This support is limited to the
Application Gateway v2 SKU.
How to configure SSL termination with Key Vault certificates by using Azure PowerShell
Responsibility : Customer
Azure Security Center monitoring : None
7.12: Manage identities securely and automatically
Guidance : Use Managed Identities to provide your Azure Application Gateway with an automatically managed
identity in Azure Active Directory (Azure AD). Managed Identities allows you to authenticate to any service that
supports Azure AD authentication, including Key Vault, without any credentials in your code.
Use Azure Key Vault to securely store certificates. Azure Key Vault is a platform-managed secret store that you
can use to safeguard secrets, keys, and SSL certificates. Azure Application Gateway supports integration with
Key Vault for server certificates that are attached to HTTPS-enabled listeners. This support is limited to the
Application Gateway v2 SKU.
How to configure SSL termination with Key Vault certificates by using Azure PowerShell
Responsibility : Customer
Azure Security Center monitoring : None
7.13: Eliminate unintended credential exposure
Guidance : Implement Credential Scanner to identify credentials within code. Credential Scanner will also
encourage moving discovered credentials to more secure locations such as Azure Key Vault.
How to setup Credential Scanner
Responsibility : Customer
Azure Security Center monitoring : None
Malware Defense
For more information, see the Azure Security Benchmark: Malware Defense.
8.1: Use centrally-managed anti-malware software
Guidance : Deploy Azure Web Application Firewall (WAF) v2 in front of critical web applications for additional
inspection of incoming traffic. Web Application Firewall (WAF) is a service (feature of Azure Application
Gateway) that provides centralized protection of your web applications from common exploits and
vulnerabilities. Azure WAF can help secure your Azure App Service web apps by inspecting inbound web traffic
to block attacks such as SQL injections, Cross-Site Scripting, malware uploads, and DDoS attacks.
Configure diagnostic settings for your Azure Application Gateway deployments. diagnostic settings are used to
configure streaming export of platform logs and metrics for a resource to the destination of your choice
(Storage Accounts, Event Hubs and Log Analytics).
How to deploy Azure WAF
How to configure diagnostic settings for Azure WAF
Responsibility : Customer
Azure Security Center monitoring : None
8.3: Ensure anti-malware software and signatures are updated
Guidance : When using Azure Web Application Firewall (WAF), you can configure WAF policies. A WAF policy
consists of two types of security rules: custom rules that are authored by the customer, and managed rule sets
that are a collection of Azure-managed pre-configured set of rules. Azure-managed rule sets provide an easy
way to deploy protection against a common set of security threats. Since such rulesets are managed by Azure,
the rules are updated as needed to protect against new attack signatures.
Understand Azure-managed WAF rule sets
Responsibility : Shared
Azure Security Center monitoring : None
Data Recovery
For more information, see the Azure Security Benchmark: Data Recovery.
9.1: Ensure regular automated back-ups
Guidance : Azure Application Gateway does not store customer data. However, if using custom Azure policy
definitions, use Azure DevOps or Azure Repos to securely store and manage your code.
Azure DevOps Services leverages many of the Azure storage features to ensure data availability in the case of
hardware failure, service disruption, or region disaster. Additionally, the Azure DevOps team follows procedures
to protect data from accidental or malicious deletion.
Understand data availability in Azure DevOps
How to store code in Azure DevOps
Azure Repos Documentation
Responsibility : Customer
Azure Security Center monitoring : None
9.2: Perform complete system backups and backup any customer-managed keys
Guidance : Back up customer-managed certificates within Azure Key Vault.
How to backup key vault certificates in Azure
Responsibility : Customer
Azure Security Center monitoring : None
9.3: Validate all backups including customer-managed keys
Guidance : Test restoration of backed up customer-managed certificates.
How to restore key vault certificates
Responsibility : Customer
Azure Security Center monitoring : None
9.4: Ensure protection of backups and customer-managed keys
Guidance : Ensure that soft delete is enabled for Azure Key Vault. Soft delete allows recovery of deleted key
vaults and vault objects such as keys, secrets, and certificates.
How to use Azure Key Vault's Soft Delete
Responsibility : Customer
Azure Security Center monitoring : None
Incident Response
For more information, see the Azure Security Benchmark: Incident Response.
10.1: Create an incident response guide
Guidance : Build out an incident response guide for your organization. Ensure that there are written incident
response plans that define all roles of personnel as well as phases of incident handling/management from
detection to post-incident review.
How to configure Workflow Automations within Azure Security Center
Guidance on building your own security incident response process
Microsoft Security Response Center's Anatomy of an Incident
Customer may also leverage NIST's Computer Security Incident Handling Guide to aid in the creation of
their own incident response plan
Responsibility : Customer
Azure Security Center monitoring : None
10.2: Create an incident scoring and prioritization procedure
Guidance : Security Center assigns a severity to each alert to help you prioritize which alerts should be
investigated first. The severity is based on how confident Security Center is in the finding or the analytics used to
issue the alert as well as the confidence level that there was malicious intent behind the activity that led to the
alert.
Additionally, clearly mark subscriptions (for ex. production, non-prod) and create a naming system to clearly
identify and categorize Azure resources.
Responsibility : Customer
Azure Security Center monitoring : None
10.3: Test security response procedures
Guidance : Conduct exercises to test your systems’ incident response capabilities on a regular cadence. Identify
weak points and gaps and revise plan as needed.
Refer to NIST's publication: Guide to Test, Training, and Exercise Programs for IT Plans and Capabilities
Responsibility : Customer
Azure Security Center monitoring : None
10.4: Provide security incident contact details and configure alert notifications for security incidents
Guidance : Security incident contact information will be used by Microsoft to contact you if the Microsoft
Security Response Center (MSRC) discovers that the customer's data has been accessed by an unlawful or
unauthorized party. Review incidents after the fact to ensure that issues are resolved.
How to set the Azure Security Center Security Contact
Responsibility : Customer
Azure Security Center monitoring : None
10.5: Incorporate security alerts into your incident response system
Guidance : Export your Azure Security Center alerts and recommendations using the Continuous Export feature.
Continuous Export allows you to export alerts and recommendations either manually or in an ongoing,
continuous fashion. You may use the Azure Security Center data connector to stream the alerts to Azure
Sentinel.
How to configure continuous export
How to stream alerts into Azure Sentinel
Responsibility : Customer
Azure Security Center monitoring : None
10.6: Automate the response to security alerts
Guidance : Use the Workflow Automation feature in Azure Security Center to automatically trigger responses
via "Logic Apps" on security alerts and recommendations.
How to configure Workflow Automation and Logic Apps
Responsibility : Customer
Azure Security Center monitoring : None
Next steps
See the Azure Security Benchmark V2 overview
Learn more about Azure security baselines
Overview of TLS termination and end to end TLS
with Application Gateway
3/5/2021 • 12 minutes to read • Edit Online
Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL), is the standard security
technology for establishing an encrypted link between a web server and a browser. This link ensures that all
data passed between the web server and browsers remain private and encrypted. Application gateway supports
both TLS termination at the gateway as well as end to end TLS encryption.
TLS termination
Application Gateway supports TLS termination at the gateway, after which traffic typically flows unencrypted to
the backend servers. There are a number of advantages of doing TLS termination at the application gateway:
Improved performance – The biggest performance hit when doing TLS decryption is the initial handshake.
To improve performance, the server doing the decryption caches TLS session IDs and manages TLS session
tickets. If this is done at the application gateway, all requests from the same client can use the cached values.
If it’s done on the backend servers, then each time the client’s requests go to a different server the client
must re authenticate. The use of TLS tickets can help mitigate this issue, but they are not supported by all
clients and can be difficult to configure and manage.
Better utilization of the backend ser vers – SSL/TLS processing is very CPU intensive, and is becoming
more intensive as key sizes increase. Removing this work from the backend servers allows them to focus on
what they are most efficient at, delivering content.
Intelligent routing – By decrypting the traffic, the application gateway has access to the request content,
such as headers, URI, and so on, and can use this data to route requests.
Cer tificate management – Certificates only need to be purchased and installed on the application gateway
and not all backend servers. This saves both time and money.
To configure TLS termination, a TLS/SSL certificate is required to be added to the listener to enable the
Application Gateway to derive a symmetric key as per TLS/SSL protocol specification. The symmetric key is then
used to encrypt and decrypt the traffic sent to the gateway. The TLS/SSL certificate needs to be in Personal
Information Exchange (PFX) format. This file format allows you to export the private key that is required by the
application gateway to perform the encryption and decryption of traffic.
IMPORTANT
The certificate on the listener requires the entire certificate chain to be uploaded (the root certificate from the CA, the
intermediates and the leaf certificate) to establish the chain of trust.
NOTE
Application gateway does not provide any capability to create a new certificate or send a certificate request to a
certification authority.
For the TLS connection to work, you need to ensure that the TLS/SSL certificate meets the following conditions:
That the current date and time is within the "Valid from" and "Valid to" date range on the certificate.
That the certificate's "Common Name" (CN) matches the host header in the request. For example, if the client
is making a request to https://www.contoso.com/ , then the CN must be www.contoso.com .
Certificates supported for TLS termination
Application gateway supports the following types of certificates:
CA (Certificate Authority) certificate: A CA certificate is a digital certificate issued by a certificate authority
(CA)
EV (Extended Validation) certificate: An EV certificate is a certificate that conforms to industry standard
certificate guidelines. This will turn the browser locator bar green and publish the company name as well.
Wildcard Certificate: This certificate supports any number of subdomains based on *.site.com, where your
subdomain would replace the *. It doesn’t, however, support site.com, so in case the users are accessing your
website without typing the leading "www", the wildcard certificate will not cover that.
Self-Signed certificates: Client browsers do not trust these certificates and will warn the user that the virtual
service’s certificate is not part of a trust chain. Self-signed certificates are good for testing or environments
where administrators control the clients and can safely bypass the browser’s security alerts. Production
workloads should never use self-signed certificates.
For more information, see configure TLS termination with application gateway.
Size of the certificate
Check the Application Gateway limits section to know the maximum TLS/SSL certificate size supported.
NOTE
The certificate added to Backend HTTP Setting to authenticate the backend servers can be the same as the certificate
added to the listener for TLS termination at application gateway or different for enhanced security.
In this example, requests using TLS1.2 are routed to backend servers in Pool1 using end to end TLS.
NOTE
In order for a TLS/SSL certificate to be trusted, that certificate of the backend server must have been issued by a CA that
is well-known. If the certificate was not issued by a trusted CA, the application gateway will then check to see if the
certificate of the issuing CA was issued by a trusted CA, and so on until either a trusted CA is found (at which point a
trusted, secure connection will be established) or no trusted CA can be found (at which point the application gateway will
mark the backend unhealthy). Therefore, it is recommended the backend server certificate contain both the root and
intermediate CAs.
If the certificate is self-signed, or signed by unknown intermediaries, then to enable end-to-end TLS in the
v2 SKU a trusted root certificate must be defined. Application Gateway only communicates with backends
whose server certificate’s root certificate matches one of the list of trusted root certificates in the backend
http setting associated with the pool.
In addition to the root certificate match, Application Gateway v2 also validates if the Host setting specified
in the backend http setting matches that of the common name (CN) presented by the backend server’s
TLS/SSL certificate. When trying to establish a TLS connection to the backend, Application Gateway v2
sets the Server Name Indication (SNI) extension to the Host specified in the backend http setting.
If pick hostname from backend target is chosen instead of the Host field in the backend http setting,
then the SNI header is always set to the backend pool FQDN and the CN on the backend server TLS/SSL
certificate must match its FQDN. Backend pool members with IPs aren't supported in this scenario.
The root certificate is a base64 encoded root certificate from the backend server certificates.
If the client specifies SNI header and all Return the appropriate certificate and Returns appropriate certificate if
the multi-site listeners are enabled if the site doesn't exist (according to available, otherwise, returns the
with "Require SNI" flag the server_name), then the connection certificate of the first HTTPS listener
is reset. configured (in the order)
If the client doesn't specify a SNI Resets the connection Returns the certificate of the first
header and if all the multi-site headers HTTPS listener configured (in the
are enabled with "Require SNI" order)
If the client doesn't specify SNI header Returns the certificate configured in Returns the certificate of the first
and if there's a basic listener the basic listener to the client (default HTTPS listener configured (in the
configured with a certificate or fallback certificate) order)
SC EN A RIO V1 V2
SNI (server_name) header during the Set as FQDN from the backend pool. SNI header (server_name) is set as the
TLS handshake as FQDN As per RFC 6066, literal IPv4 and IPv6 hostname from the custom probe
addresses are not permitted in SNI attached to the HTTP settings (if
hostname. configured), otherwise from the
Note: FQDN in the backend pool hostname mentioned in the HTTP
should DNS resolve to backend settings, otherwise from the FQDN
server’s IP address (public or private) mentioned in the backend pool. The
order of precedence is custom probe >
HTTP settings > backend pool.
Note: If the hostnames configured in
HTTP settings and custom probe are
different, then according to the
precedence, SNI will be set as the
hostname from the custom probe.
If the backend pool address is an IP SNI (server_name) won’t be set. In the order of precedence mentioned
address (v1) or if custom probe Note: In this case, the backend server previously, if they have IP address as
hostname is configured as IP address should be able to return a hostname, then SNI won't be set as
(v2) default/fallback certificate and this per RFC 6066.
should be allow listed in HTTP settings Note: SNI also won't be set in v2
under authentication certificate. If probes if no custom probe is
there’s no default/fallback certificate configured and no hostname is set on
configured in the backend server and HTTP settings or backend pool
SNI is expected, the server might reset
the connection and will lead to probe
failures
NOTE
If a custom probe is not configured, then Application Gateway sends a default probe in this format -
<protocol>://127.0.0.1:<port>/. For example, for a default HTTPS probe, it'll be sent as https://127.0.0.1:443/. Note that,
the 127.0.0.1 mentioned here is only used as HTTP host header and as per RFC 6066, will not be used as SNI header. For
more information on health probe errors, check the backend health troubleshooting guide.
SNI (server_name) header during the Set as FQDN from the backend pool. SNI header (server_name) is set as the
TLS handshake as FQDN As per RFC 6066, literal IPv4 and IPv6 hostname from the HTTP settings,
addresses are not permitted in SNI otherwise, if
hostname. PickHostnameFromBackendAddress
Note: FQDN in the backend pool option is chosen or if no hostname is
should DNS resolve to backend mentioned, then it'll be set as the
server’s IP address (public or private) FQDN in the backend pool
configuration
If the backend pool address is an IP SNI won't be set as per RFC 6066 if the SNI will be set as the hostname from
address or hostname is not set in backend pool entry is not an FQDN the input FQDN from the client and
HTTP settings the backend certificate's CN has to
match with this hostname.
Next steps
After learning about end to end TLS, go to Configure end to end TLS by using Application Gateway with
PowerShell to create an application gateway using end to end TLS.
Application Gateway TLS policy overview
3/5/2021 • 3 minutes to read • Edit Online
You can use Azure Application Gateway to centralize TLS/SSL certificate management and reduce encryption
and decryption overhead from a back-end server farm. This centralized TLS handling also lets you specify a
central TLS policy that's suited to your organizational security requirements. This helps you meet compliance
requirements as well as security guidelines and recommended practices.
The TLS policy includes control of the TLS protocol version as well as the cipher suites and the order in which
ciphers are used during a TLS handshake. Application Gateway offers two mechanisms for controlling TLS
policy. You can use either a predefined policy or a custom policy.
Known issue
Application Gateway v2 does not support the following DHE ciphers and these won't be used for the TLS
connections with clients even though they are mentioned in the predefined policies. Instead of DHE ciphers,
secure and faster ECDHE ciphers are recommended.
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
TLS_DHE_RSA_WITH_AES_128_CBC_SHA
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
TLS_DHE_RSA_WITH_AES_256_CBC_SHA
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
TLS_DHE_DSS_WITH_AES_128_CBC_SHA
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
TLS_DHE_DSS_WITH_AES_256_CBC_SHA
AppGwSslPolicy20150501
P RO P ERT Y VA L UE
Name AppGwSslPolicy20150501
MinProtocolVersion TLSv1_0
CipherSuites TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
TLS_DHE_RSA_WITH_AES_256_CBC_SHA
TLS_DHE_RSA_WITH_AES_128_CBC_SHA
TLS_RSA_WITH_AES_256_GCM_SHA384
TLS_RSA_WITH_AES_128_GCM_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA256
TLS_RSA_WITH_AES_128_CBC_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
TLS_DHE_DSS_WITH_AES_256_CBC_SHA
TLS_DHE_DSS_WITH_AES_128_CBC_SHA
TLS_RSA_WITH_3DES_EDE_CBC_SHA
TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
AppGwSslPolicy20170401
P RO P ERT Y VA L UE
Name AppGwSslPolicy20170401
MinProtocolVersion TLSv1_1
Default False
CipherSuites TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_256_GCM_SHA384
TLS_RSA_WITH_AES_128_GCM_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA256
TLS_RSA_WITH_AES_128_CBC_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_128_CBC_SHA
AppGwSslPolicy20170401S
P RO P ERT Y VA L UE
Name AppGwSslPolicy20170401S
MinProtocolVersion TLSv1_2
Default False
CipherSuites TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_256_GCM_SHA384
TLS_RSA_WITH_AES_128_GCM_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA256
TLS_RSA_WITH_AES_128_CBC_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_128_CBC_SHA
IMPORTANT
If you are using a custom SSL policy in Application Gateway v1 SKU (Standard or WAF), make sure that you add the
mandatory cipher "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" to the list. This cipher is required to enable metrics
and logging in the Application Gateway v1 SKU. This is not mandatory for Application Gateway v2 SKU (Standard_v2 or
WAF_v2).
NOTE
TLS cipher suites used for the connection are also based on the type of the certificate being used. In client to application
gateway connections, the cipher suites used are based on the type of server certificates on the application gateway
listener. In application gateway to backend pool connections, the cipher suites used are based on the type of server
certificates on the backend pool servers.
Next steps
If you want to learn to configure a TLS policy, see Configure TLS policy versions and cipher suites on Application
Gateway.
Overview of mutual authentication with Application
Gateway (Preview)
4/2/2021 • 4 minutes to read • Edit Online
Mutual authentication, or client authentication, allows for the Application Gateway to authenticate the client
sending requests. Usually only the client is authenticating the Application Gateway; mutual authentication allows
for both the client and the Application Gateway to authenticate each other.
NOTE
We recommend using TLS 1.2 with mutual authentication as TLS 1.2 will be mandated in the future.
Mutual authentication
Application Gateway supports certificate based mutual authentication where you can upload a trusted client CA
certificate(s) to the Application Gateway and the gateway will use that certificate to authenticate the client
sending a request to the gateway. With the rise in IoT use cases and increased security requirements across
industries, mutual authentication provides a way for you to manage and control which clients can talk to your
Application Gateway.
To configure mutual authentication, a trusted client CA certificate is required to be uploaded as part of the client
authentication portion of an SSL profile. The SSL profile will then need to be associated to a listener in order to
complete configuration of mutual authentication. There must always be a root CA certificate in the client
certificate that you upload. You can upload a certificate chain as well, but the chain must include a root CA
certificate in addition to as many intermediate CA certificates as you'd like.
For example, if your client certificate contains a root CA certificate, multiple intermediate CA certificates, and a
leaf certificate, make sure that the root CA certificate and all the intermediate CA certificates are uploaded onto
Application Gateway in one file. For more information on how to extract a trusted client CA certificate, see how
to extract trusted client CA certificates.
If you're uploading a certificate chain with root CA and intermediate CA certificates, the certificate chain must be
uploaded as a PEM or CER file to the gateway.
NOTE
Mutual authentication is only available on Standard_v2 and WAF_v2 SKUs.
IMPORTANT
Make sure you upload the entire trusted client CA certificate chain to the Application Gateway when using mutual
authentication.
IMPORTANT
We recommend only uploading one certificate chain per file. This is especially important if you enable verify client
certificate DN. By uploading multiple certificate chains in one file, you will end up in scenario four or five and may run into
issues later down the line when the client certificate presented doesn't match the client certificate issuer DN Application
Gateway extracted from the chains.
For more information on how to extract trusted client CA certificate chains, see how to extract trusted client CA
certificate chains.
Server variables
With mutual authentication, there are additional server variables that you can use to pass information about the
client certificate to the backend servers behind the Application Gateway. For more information about which
server variables are available and how to use them, check out server variables.
Next steps
After learning about mutual authentication, go to Configure Application Gateway with mutual authentication in
PowerShell to create an Application Gateway using mutual authentication.
TLS termination with Key Vault certificates
3/22/2021 • 4 minutes to read • Edit Online
Azure Key Vault is a platform-managed secret store that you can use to safeguard secrets, keys, and TLS/SSL
certificates. Azure Application Gateway supports integration with Key Vault for server certificates that are
attached to HTTPS-enabled listeners. This support is limited to the v2 SKU of Application Gateway.
Key Vault integration offers two models for TLS termination:
You can explicitly provide TLS/SSL certificates attached to the listener. This model is the traditional way to
pass TLS/SSL certificates to Application Gateway for TLS termination.
You can optionally provide a reference to an existing Key Vault certificate or secret when you create an
HTTPS-enabled listener.
Application Gateway integration with Key Vault offers many benefits, including:
Stronger security, because TLS/SSL certificates aren't directly handled by the application development team.
Integration allows a separate security team to:
Set up application gateways.
Control application gateway lifecycles.
Grant permissions to selected application gateways to access certificates that are stored in your key
vault.
Support for importing existing certificates into your key vault. Or use Key Vault APIs to create and manage
new certificates with any of the trusted Key Vault partners.
Support for automatic renewal of certificates that are stored in your key vault.
Application Gateway currently supports software-validated certificates only. Hardware security module (HSM)-
validated certificates are not supported. After Application Gateway is configured to use Key Vault certificates, its
instances retrieve the certificate from Key Vault and install them locally for TLS termination. The instances also
poll Key Vault at 4-hour intervals to retrieve a renewed version of the certificate, if it exists. If an updated
certificate is found, the TLS/SSL certificate currently associated with the HTTPS listener is automatically rotated.
NOTE
The Azure portal only supports KeyVault Certificates, not secrets. Application Gateway still supports referencing secrets
from KeyVault, but only through non-Portal resources like PowerShell, CLI, API, ARM templates, etc.
IMPORTANT
Starting March 15th 2021, Key Vault recognizes Azure Application Gateway as one of the Trusted Services, thus
allowing you to build a secure network boundary in Azure. This gives you an ability to deny access to traffic from
all networks (including internet traffic) to Key Vault but still make it accessible for Application Gateway resource
under your subscription.
You can configure your Application Gateway in a restricted network of Key Vault in the following
manner.
a) Under Key Vault’s Networking blade
b) choose Private endpoint and selected networks in "Firewall and Virtual Networks" tab
c) then using Virtual Networks, add your Application Gateway’s virtual network and Subnet. During
the process also configure ‘Microsoft.KeyVault' service endpoint by selecting its checkbox.
d) Finally, select “Yes” to allow Trusted Services to bypass Key Vault’s firewall.
NOTE
If you deploy the application gateway via an ARM template, either by using the Azure CLI or PowerShell, or via an
Azure application deployed from the Azure portal, the SSL certificate is stored in the key vault as a base64-
encoded PFX file. You must complete the steps in Use Azure Key Vault to pass secure parameter value during
deployment.
It's particularly important to set enabledForTemplateDeployment to true . The certificate may be passwordless
or it may have a password. In the case of a certificate with a password, the following example shows a possible
configuration for the sslCertificates entry in the properties for the ARM template configuration for an app
gateway. The values of appGatewaySSLCertificateData and appGatewaySSLCertificatePassword are looked
up from the key vault as described in the section Reference secrets with dynamic ID. Follow the references
backward from parameters('secretName') to see how the lookup happens. If the certificate is passwordless,
omit the password entry.
"sslCertificates": [
{
"name": "appGwSslCertificate",
"properties": {
"data": "[parameters('appGatewaySSLCertificateData')]",
"password": "[parameters('appGatewaySSLCertificatePassword')]"
}
}
]
Next steps
Configure TLS termination with Key Vault certificates by using Azure PowerShell
What is Application Gateway Ingress Controller?
3/5/2021 • 3 minutes to read • Edit Online
The Application Gateway Ingress Controller (AGIC) is a Kubernetes application, which makes it possible for
Azure Kubernetes Service (AKS) customers to leverage Azure's native Application Gateway L7 load-balancer to
expose cloud software to the Internet. AGIC monitors the Kubernetes cluster it is hosted on and continuously
updates an Application Gateway, so that selected services are exposed to the Internet.
The Ingress Controller runs in its own pod on the customer’s AKS. AGIC monitors a subset of Kubernetes
Resources for changes. The state of the AKS cluster is translated to Application Gateway specific configuration
and applied to the Azure Resource Manager (ARM).
AGIC is configured via the Kubernetes Ingress resource, along with Service and Deployments/Pods. It provides a
number of features, leveraging Azure’s native Application Gateway L7 load balancer. To name a few:
URL routing
Cookie-based affinity
TLS termination
End-to-end TLS
Support for public, private, and hybrid web sites
Integrated web application firewall
NOTE
Customers can only deploy one AGIC add-on per AKS cluster, and each AGIC add-on currently can only target one
Application Gateway. For deployments that require more than one AGIC per cluster or multiple AGICs targeting one
Application Gateway, please continue to use AGIC deployed through Helm.
Next steps
AKS Add-On Greenfield Deployment : Instructions on installing AGIC add-on, AKS, and Application
Gateway on blank-slate infrastructure.
AKS Add-On Brownfield Deployment : Install AGIC add-on on an AKS cluster with an existing Application
Gateway.
Helm Greenfield Deployment : Install AGIC through Helm, new AKS cluster, and new Application Gateway
on blank-slate infrastructure.
Helm Brownfield Deployment : Deploy AGIC through Helm on an existing AKS cluster and Application
Gateway.
Application Gateway health monitoring overview
11/2/2020 • 6 minutes to read • Edit Online
Azure Application Gateway by default monitors the health of all resources in its back-end pool and automatically
removes any resource considered unhealthy from the pool. Application Gateway continues to monitor the
unhealthy instances and adds them back to the healthy back-end pool once they become available and respond
to health probes. By default, Application gateway sends the health probes with the same port that is defined in
the back-end HTTP settings. A custom probe port can be configured using a custom health probe.
The source IP address Application Gateway uses for health probes depends on the backend pool:
If the server address in the backend pool is a public endpoint, then the source address is the application
gateway's frontend public IP address.
If the server address in the backend pool is a private endpoint, then the source IP address is from the
application gateway subnet's private IP address space.
In addition to using default health probe monitoring, you can also customize the health probe to suit your
application's requirements. In this article, both default and custom health probes are covered.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
The default probe looks only at <protocol>://127.0.0.1:<port> to determine health status. If you need to
configure the health probe to go to a custom URL or modify any other settings, you must use custom probes.
For more information about HTTPS probes, see Overview of TLS termination and end to end TLS with
Application Gateway.
Probe intervals
All instances of Application Gateway probe the backend independent of each other. The same probe
configuration applies to each Application Gateway instance. For example, if the probe configuration is to send
health probes every 30 seconds and the application gateway has two instances, then both instances send the
health probe every 30 seconds.
Also if there are multiple listeners, then each listener probes the backend independent of each other. For
example, if there are two listeners pointing to the same backend pool on two different ports (configured by two
backend http settings) then each listener probes the same backend independently. In this case, there are two
probes from each application gateway instance for the two listeners. If there are two instances of the application
gateway in this scenario, the backend virtual machine would see four probes per the configured probe interval.
Custom health probe
Custom probes allow you to have more granular control over the health monitoring. When using custom
probes, you can configure a custom hostname, URL path, probe interval, and how many failed responses to
accept before marking the back-end pool instance as unhealthy, etc.
Custom health probe settings
The following table provides definitions for the properties of a custom health probe.
Name Name of the probe. This name is used to identify and refer
to the probe in back-end HTTP settings.
Protocol Protocol used to send the probe. This has to match with the
protocol defined in the back-end HTTP settings it is
associated to
Host Host name to send the probe with. In v1 SKU, this value will
be used only for the host header of the probe request. In v2
SKU, it will be used both as host header as well as SNI
Path Relative path of the probe. A valid path starts with '/'
Unhealthy threshold Probe retry count. The back-end server is marked down
after the consecutive probe failure count reaches the
unhealthy threshold
Probe matching
By default, an HTTP(S) response with status code between 200 and 399 is considered healthy. Custom health
probes additionally support two matching criteria. Matching criteria can be used to optionally modify the default
interpretation of what makes a healthy response.
The following are matching criteria:
HTTP response status code match - Probe matching criterion for accepting user specified http response
code or response code ranges. Individual comma-separated response status codes or a range of status code
is supported.
HTTP response body match - Probe matching criterion that looks at HTTP response body and matches
with a user specified string. The match only looks for presence of user specified string in response body and
isn't a full regular expression match.
Match criteria can be specified using the New-AzApplicationGatewayProbeHealthResponseMatch cmdlet.
For example:
$match = New-AzApplicationGatewayProbeHealthResponseMatch -StatusCode 200-399
$match = New-AzApplicationGatewayProbeHealthResponseMatch -Body "Healthy"
Once the match criteria is specified, it can be attached to probe configuration using a -Match parameter in
PowerShell.
NSG considerations
You must allow incoming Internet traffic on TCP ports 65503-65534 for the Application Gateway v1 SKU, and
TCP ports 65200-65535 for the v2 SKU with the destination subnet as Any and source as GatewayManager
service tag. This port range is required for Azure infrastructure communication.
Additionally, outbound Internet connectivity can't be blocked, and inbound traffic coming from the
AzureLoadBalancer tag must be allowed.
For more information, see Application Gateway configuration overview.
Next steps
After learning about Application Gateway health monitoring, you can configure a custom health probe in the
Azure portal or a custom health probe using PowerShell and the Azure Resource Manager deployment model.
Back-end health and diagnostic logs for Application
Gateway
3/24/2021 • 13 minutes to read • Edit Online
You can monitor Azure Application Gateway resources in the following ways:
Back-end health: Application Gateway provides the capability to monitor the health of the servers in the
back-end pools through the Azure portal and through PowerShell. You can also find the health of the
back-end pools through the performance diagnostic logs.
Logs: Logs allow for performance, access, and other data to be saved or consumed from a resource for
monitoring purposes.
Metrics: Application Gateway has several metrics which help you verify that your system is performing as
expected.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Back-end health
Application Gateway provides the capability to monitor the health of individual members of the back-end pools
through the portal, PowerShell, and the command-line interface (CLI). You can also find an aggregated health
summary of back-end pools through the performance diagnostic logs.
The back-end health report reflects the output of the Application Gateway health probe to the back-end
instances. When probing is successful and the back end can receive traffic, it's considered healthy. Otherwise, it's
considered unhealthy.
IMPORTANT
If there is a network security group (NSG) on an Application Gateway subnet, open port ranges 65503-65534 for v1
SKUs, and 65200-65535 for v2 SKUs on the Application Gateway subnet for inbound traffic. This port range is required
for Azure infrastructure communication. They are protected (locked down) by Azure certificates. Without proper
certificates, external entities, including the customers of those gateways, will not be able to initiate any changes on those
endpoints.
Results
The following snippet shows an example of the response:
{
"BackendAddressPool": {
"Id": "/subscriptions/00000000-0000-0000-
000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/applicationGateways/applicationGateway1/ba
ckendAddressPools/appGatewayBackendPool"
},
"BackendHttpSettingsCollection": [
{
"BackendHttpSettings": {
"Id": "/00000000-0000-0000-
000000000000/resourceGroups/ContosoRG/providers/Microsoft.Network/applicationGateways/applicationGateway1/ba
ckendHttpSettingsCollection/appGatewayBackendHttpSettings"
},
"Servers": [
{
"Address": "hostname.westus.cloudapp.azure.com",
"Health": "Healthy"
},
{
"Address": "hostname.westus.cloudapp.azure.com",
"Health": "Healthy"
}
]
}
]
}
Diagnostic logs
You can use different types of logs in Azure to manage and troubleshoot application gateways. You can access
some of these logs through the portal. All logs can be extracted from Azure Blob storage and viewed in different
tools, such as Azure Monitor logs, Excel, and Power BI. You can learn more about the different types of logs from
the following list:
Activity log : You can use Azure activity logs (formerly known as operational logs and audit logs) to view all
operations that are submitted to your Azure subscription, and their status. Activity log entries are collected by
default, and you can view them in the Azure portal.
Access log : You can use this log to view Application Gateway access patterns and analyze important
information. This includes the caller's IP, requested URL, response latency, return code, and bytes in and out.
An access log is collected every 60 seconds. This log contains one record per instance of Application
Gateway. The Application Gateway instance is identified by the instanceId property.
Performance log : You can use this log to view how Application Gateway instances are performing. This log
captures performance information for each instance, including total requests served, throughput in bytes,
total requests served, failed request count, and healthy and unhealthy back-end instance count. A
performance log is collected every 60 seconds. The Performance log is available only for the v1 SKU. For the
v2 SKU, use Metrics for performance data.
Firewall log : You can use this log to view the requests that are logged through either detection or
prevention mode of an application gateway that is configured with the web application firewall. Firewall logs
are collected every 60 seconds.
NOTE
Logs are available only for resources deployed in the Azure Resource Manager deployment model. You cannot use logs for
resources in the classic deployment model. For a better understanding of the two models, see the Understanding
Resource Manager deployment and classic deployment article.
TIP
Activity logs do not require a separate storage account. The use of storage for access and performance logging incurs
service charges.
3. The Diagnostics settings page provides the settings for the diagnostic logs. In this example, Log
Analytics stores the logs. You can also use event hubs and a storage account to save the diagnostic logs.
4. Type a name for the settings, confirm the settings, and select Save .
Activity log
Azure generates the activity log by default. The logs are preserved for 90 days in the Azure event logs store.
Learn more about these logs by reading the View events and activity log article.
Access log
The access log is generated only if you've enabled it on each Application Gateway instance, as detailed in the
preceding steps. The data is stored in the storage account that you specified when you enabled the logging. Each
access of Application Gateway is logged in JSON format as shown below.
For Application Gateway Standard and WAF SKU (v1)
VA L UE DESC RIP T IO N
RequestQuery Ser ver-Routed : Back-end pool instance that was sent the
request.
X-AzureApplicationGateway-LOG-ID : Correlation ID
used for the request. It can be used to troubleshoot traffic
issues on the back-end servers.
SERVER-STATUS: HTTP response code that Application
Gateway received from the back end.
host The hostname with which the request has been sent to the
backend server. If backend hostname is being overridden,
this name will reflect that.
originalHost The hostname with which the request was received by the
Application Gateway from the client.
{
"resourceId":
"/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/PEERINGTEST/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/
{applicationGatewayName}",
"operationName": "ApplicationGatewayAccess",
"time": "2017-04-26T19:27:38Z",
"category": "ApplicationGatewayAccessLog",
"properties": {
"instanceId": "ApplicationGatewayRole_IN_0",
"clientIP": "191.96.249.97",
"clientPort": 46886,
"httpMethod": "GET",
"requestUri": "/phpmyadmin/scripts/setup.php",
"requestQuery": "X-AzureApplicationGateway-CACHE-HIT=0&SERVER-ROUTED=10.4.0.4&X-
AzureApplicationGateway-LOG-ID=874f1f0f-6807-41c9-b7bc-f3cfa74aa0b1&SERVER-STATUS=404",
"userAgent": "-",
"httpStatus": 404,
"httpVersion": "HTTP/1.0",
"receivedBytes": 65,
"sentBytes": 553,
"timeTaken": 205,
"sslEnabled": "off",
"host": "www.contoso.com",
"originalHost": "www.contoso.com"
}
}
VA L UE DESC RIP T IO N
sslCipher Cipher suite being used for TLS communication (if TLS is
enabled).
requestUri This field contains the URL after the rewrite operation on
Application Gateway
{
"resourceId":
"/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/PEERINGTEST/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONGATEWAYS/
{applicationGatewayName}",
"operationName": "ApplicationGatewayAccess",
"time": "2017-04-26T19:27:38Z",
"category": "ApplicationGatewayAccessLog",
"properties": {
"instanceId": "appgw_1",
"clientIP": "191.96.249.97",
"httpMethod": "GET",
"requestUri": "/phpmyadmin/scripts/setup.php",
"userAgent": "-",
"httpStatus": 404,
"httpVersion": "HTTP/1.0",
"receivedBytes": 65,
"sentBytes": 553,
"timeTaken": 205,
"sslEnabled": "off",
"sslCipher": "",
"sslProtocol": "",
"serverRouted": "104.41.114.59:80",
"serverStatus": "200",
"serverResponseLatency": "0.023",
"host": "www.contoso.com",
}
}
Performance log
The performance log is generated only if you have enabled it on each Application Gateway instance, as detailed
in the preceding steps. The data is stored in the storage account that you specified when you enabled the
logging. The performance log data is generated in 1-minute intervals. It is available only for the v1 SKU. For the
v2 SKU, use Metrics for performance data. The following data is logged:
VA L UE DESC RIP T IO N
{
"resourceId":
"/SUBSCRIPTIONS/{subscriptionId}/RESOURCEGROUPS/{resourceGroupName}/PROVIDERS/MICROSOFT.NETWORK/APPLICATIONG
ATEWAYS/{applicationGatewayName}",
"operationName": "ApplicationGatewayPerformance",
"time": "2016-04-09T00:00:00Z",
"category": "ApplicationGatewayPerformanceLog",
"properties":
{
"instanceId":"ApplicationGatewayRole_IN_1",
"healthyHostCount":"4",
"unHealthyHostCount":"0",
"requestCount":"185",
"latency":"0",
"failedRequestCount":"0",
"throughput":"119427"
}
}
NOTE
Latency is calculated from the time when the first byte of the HTTP request is received to the time when the last byte of
the HTTP response is sent. It's the sum of the Application Gateway processing time plus the network cost to the back end,
plus the time that the back end takes to process the request.
Firewall log
The firewall log is generated only if you have enabled it for each application gateway, as detailed in the
preceding steps. This log also requires that the web application firewall is configured on an application gateway.
The data is stored in the storage account that you specified when you enabled the logging. The following data is
logged:
VA L UE DESC RIP T IO N
ruleSetVersion Rule set version used. Available values are 2.2.9 and 3.0.
site Site for which the log was generated. Currently, only Global
is listed because rules are global.
TIP
If you are familiar with Visual Studio and basic concepts of changing values for constants and variables in C#, you can use
the log converter tools available from GitHub.
Next steps
Visualize counter and event logs by using Azure Monitor logs.
Visualize your Azure activity log with Power BI blog post.
View and analyze Azure activity logs in Power BI and more blog post.
Metrics for Application Gateway
3/5/2021 • 9 minutes to read • Edit Online
Application Gateway publishes data points, called metrics, to Azure Monitor for the performance of your
Application Gateway and backend instances. These metrics are numerical values in an ordered set of time-series
data that describe some aspect of your application gateway at a particular time. If there are requests flowing
through the Application Gateway, it measures and sends its metrics in 60-second intervals. If there are no
requests flowing through the Application Gateway or no data for a metric, the metric is not reported. For more
information, see Azure Monitor metrics.
NOTE
If there are more than one listener in the Application Gateway, then always filter by Listener dimension while comparing
different latency metrics in order to get meaningful inference.
Metrics visualization
Browse to an application gateway, under Monitoring select Metrics . To view the available values, select the
METRIC drop-down list.
In the following image, you see an example with three metrics displayed for the last 30 minutes:
To see a current list of metrics, see Supported metrics with Azure Monitor.
Alert rules on metrics
You can start alert rules based on metrics for a resource. For example, an alert can call a webhook or email an
administrator if the throughput of the application gateway is above, below, or at a threshold for a specified
period.
The following example walks you through creating an alert rule that sends an email to an administrator after
throughput breaches a threshold:
1. select Add metric aler t to open the Add rule page. You can also reach this page from the metrics page.
2. On the Add rule page, fill out the name, condition, and notify sections, and select OK .
In the Condition selector, select one of the four values: Greater than , Greater than or equal ,
Less than , or Less than or equal to .
In the Period selector, select a period from five minutes to six hours.
If you select Email owners, contributors, and readers , the email can be dynamic based on the
users who have access to that resource. Otherwise, you can provide a comma-separated list of
users in the Additional administrator email(s) box.
If the threshold is breached, an email that's similar to the one in the following image arrives:
A list of alerts appears after you create a metric alert. It provides an overview of all the alert rules.
Next steps
Visualize counter and event logs by using Azure Monitor logs.
Visualize your Azure activity log with Power BI blog post.
View and analyze Azure activity logs in Power BI and more blog post.
Application Gateway support for multi-tenant back
ends such as App service
3/5/2021 • 4 minutes to read • Edit Online
In multi-tenant architectural designs in web servers, multiple websites are running on the same web server
instance. Hostnames are used to differentiate between the different applications which are hosted. By default,
application gateway does not change the incoming HTTP host header from the client and sends the header
unaltered to the back end. This works well for backend pool members such as NICs, virtual machine scale sets,
public IP addresses, internal IP addresses and FQDN as these do not rely on a specific host header or SNI
extension to resolve to the correct endpoint. However, there are many services such as Azure App service web
apps and Azure API management that are multi-tenant in nature and rely on a specific host header or SNI
extension to resolve to the correct endpoint. Usually, the DNS name of the application, which in turn is the DNS
name associated with the application gateway, is different from the domain name of the backend service.
Therefore, the host header in the original request received by the application gateway is not the same as the
host name of the backend service. Because of this, unless the host header in the request from the application
gateway to the backend is changed to the host name of the backend service, the multi-tenant backends are not
able to resolve the request to the correct endpoint.
Application gateway provides a capability which allows users to override the HTTP host header in the request
based on the host name of the back-end. This capability enables support for multi-tenant back ends such as
Azure App service web apps and API management. This capability is available for both the v1 and v2 standard
and WAF SKUs.
NOTE
This is not applicable to Azure App service environment (ASE) since ASE is a dedicated resource unlike Azure App service
which is a multi-tenant resource.
With this capability, customers specify the options in the HTTP settings and custom probes to the appropriate
configuration. This setting is then tied to a listener and a back-end pool by using a rule.
Special considerations
TLS termination and end to end TLS with multi-tenant services
Both TLS termination and end to end TLS encryption is supported with multi-tenant services. For TLS
termination at the application gateway, TLS certificate continues to be required to be added to the application
gateway listener. However, in case of end to end TLS, trusted Azure services such as Azure App service web apps
do not require allowing the backends in the application gateway. Therefore, there is no need to add any
authentication certificates.
Notice that in the above image, there is no requirement to add authentication certificates when App service is
selected as backend.
Health probe
Overriding the host header in the HTTP settings only affects the request and its routing. it does not impact the
health probe behavior. For end to end functionality to work, both the probe and the HTTP settings must be
modified to reflect the correct configuration. In addition to providing the ability to specify a host header in the
probe configuration, custom probes also support the ability to derive the host header from the currently
configured HTTP settings. This configuration can be specified by using the PickHostNameFromBackendHttpSettings
parameter in the probe configuration.
Redirection to App Service’s URL scenario
There can be scenarios where the hostname in the response from the App service may direct the end-user
browser to the *.azurewebsites.net hostname instead of the domain associated with the Application Gateway.
This issue may happen when:
You have redirection configured on your App Service. Redirection can be as simple as adding a trailing slash
to the request.
You have Azure AD authentication which causes the redirection.
To resolve such cases, see Troubleshoot redirection to App service’s URL issue.
Next steps
Learn how to set up an application gateway with a multi-tenant app such as Azure App service web app as a
back-end pool member by visiting Configure App Service web apps with Application Gateway
Overview of WebSocket support in Application
Gateway
11/2/2020 • 3 minutes to read • Edit Online
Application Gateway provides native support for WebSocket across all gateway sizes. There is no user-
configurable setting to selectively enable or disable WebSocket support.
WebSocket protocol standardized in RFC6455 enables a full duplex communication between a server and a
client over a long running TCP connection. This feature allows for a more interactive communication between
the web server and the client, which can be bidirectional without the need for polling as required in HTTP-based
implementations. WebSocket has low overhead unlike HTTP and can reuse the same TCP connection for
multiple request/responses resulting in a more efficient utilization of resources. WebSocket protocols are
designed to work over traditional HTTP ports of 80 and 443.
You can continue using a standard HTTP listener on port 80 or 443 to receive WebSocket traffic. WebSocket
traffic is then directed to the WebSocket enabled backend server using the appropriate backend pool as
specified in application gateway rules. The backend server must respond to the application gateway probes,
which are described in the health probe overview section. Application gateway health probes are HTTP/HTTPS
only. Each backend server must respond to HTTP probes for application gateway to route WebSocket traffic to
the server.
It's used in apps that benefit from fast, real-time communication, such as chat, dashboard, and game apps.
}, {
"name": "<ruleName2>",
"properties": {
"RuleType": "Basic",
"httpListener": {
"id":
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationG
ateways/{applicationGatewayName}/httpListeners/appGatewayHttpListener')]"
},
"backendAddressPool": {
"id":
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationG
ateways/{applicationGatewayName}/backendAddressPools/ContosoServerPool')]"
},
"backendHttpSettings": {
"id":
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationG
ateways/{applicationGatewayName}/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
}
}
}]
Another reason for this is that application gateway backend health probe supports HTTP and HTTPS protocols
only. If the backend server does not respond to HTTP or HTTPS probes, it is taken out of backend pool.
Next steps
After learning about WebSocket support, go to create an application gateway to get started with a WebSocket
enabled web application.
Understanding Pricing for Azure Application
Gateway and Web Application Firewall
3/5/2021 • 14 minutes to read • Edit Online
NOTE
Prices shown in this article are examples and are for illustration purposes only. For pricing information according to your
region, see the Pricing page.
Azure Application Gateway is a layer 7 load-balancing solution, which enables scalable, highly available, and
secure web application delivery on Azure.
There are no upfront costs or termination costs associated with Application Gateway. You will be billed only for
the resources pre-provisioned and utilized based on actual hourly consumption. Costs associated with
Application Gateway are classified into two components: fixed costs and variable costs. Actual costs within each
component will vary according to the SKU being utilized.
This article describes the costs associated with each SKU and it is recommended that users utilize this document
for planning and managing costs associated with the Azure Application Gateway.
V1 SKUs
Standard Application Gateway and WAF V1 SKUs are billed as a combination of:
Fixed Cost
Cost based on the time a particular type of Application Gateway/WAF is provisioned and running for
processing requests. The fixed cost component takes in consideration the following factors:
Tier - Standard Application Gateway or WAF
Size - Small, Medium & Large
Instance Count - Number of instances to be deployed
For N instances, the costs associated will be N * cost of one Instance of a particular Tier(Standard & WAF)
& Size(Small, Medium & Large) combination.
Variable Cost
Cost based on the amount of data processed by the Application Gateway/WAF. Both the request and
response bytes processed by the Application Gateway would be considered for billing.
Total Cost = Fixed Cost + Variable Cost
Standard Application Gateway
Fixed Cost & Variable Cost will be calculated according to the Application Gateway type. The following table
shows example prices based on a snapshot of East US pricing and are meant for illustration purposes only.
Fixed Cost (East US region pricing)
A P P L IC AT IO N GAT EWAY T Y P E C O ST S ( $/ H R)
Small $0.025
A P P L IC AT IO N GAT EWAY T Y P E C O ST S ( $/ H R)
Medium $0.07
Large $0.32
Monthly price estimates are based on 730 hours of usage per month.
Variable Cost (East US region pricing)
For more pricing information according to your region, see the pricing page.
WAF V1
Fixed Cost & Variable Costs will be calculated according to the provisioned Application Gateway type.
The following table shows example prices based on a snapshot of East US pricing and are for illustration
purposes only.
Fixed Cost (East US region pricing)
A P P L IC AT IO N GAT EWAY T Y P E C O ST S ( $/ H R)
Small NA
Medium $0.126
Large $0.448
Monthly price estimates are based on 730 hours of usage per month.
Variable Cost (East US region pricing)
For more pricing information according to your region, see the pricing page.
NOTE
Outbound data transfers - data going out of Azure data centers from application gateways will be charged at standard
data transfer rates.
Example 1 (a) – Standard Application Gateway with 1 instance count
Let’s assume you’ve provisioned a standard Application Gateway of medium type with 1 instance and it
processes 500 GB in a month. Your Application Gateway costs using the pricing mentioned above would be
calculated as follows:
Fixed Price = $0.07 * 730 (Hours) = $51.1 Monthly price estimates are based on 730 hours of usage per month.
Variable Costs = Free (Medium tier has no costs for the first 10 TB processed per month) Total Costs = $51.1 + 0
= $51.1
NOTE
To support high availability scenarios, it is required to setup a minimum of 2 instances for V1 SKUs. See SLA for
Application Gateway
V2 SKUs
Application Gateway V2 and WAF V2 SKUs support autoscaling and guarantee high availability by default.
Key Terms
Capac i t y Un i t
Capacity Unit is the measure of capacity utilization for an Application Gateway across multiple parameters.
A single Capacity Unit consists of the following parameters:
2500 Persistent connections
2.22-Mbps throughput
1 Compute Unit
If any one of these parameters are exceeded, then another n capacity unit(s) are necessary, even if the other two
parameters don’t exceed this single capacity unit’s limits. The parameter with the highest utilization among the
three above will be internally used for calculating capacity units, which is in turn billed.
Com pu t e Un i t
Compute Unit is the measure of compute capacity consumed. Factors affecting compute unit consumption are
TLS connections/sec, URL Rewrite computations, and WAF rule processing. The number of requests a compute
unit can handle depends on various criteria like TLS certificate key size, key exchange algorithm, header rewrites,
and in case of WAF - incoming request size.
Compute unit guidance:
Standard_v2 - Each compute unit is capable of approximately 50 connections per second with RSA 2048-
bit key TLS certificate.
WAF_v2 - Each compute unit can support approximately 10 concurrent requests per second for 70-30%
mix of traffic with 70% requests less than 2 KB GET/POST and remaining higher. WAF performance is not
affected by response size currently.
I n st a n c e C o u n t
Pre-provisioning of resources for Application Gateway V2 SKUs is defined in terms of instance count. Each
instance guarantees a minimum of 10 capacity units in terms of processing capability. The same instance could
potentially support more than 10 capacity units for different traffic patterns depending upon the Capacity Unit
parameters.
Manually defined scale and limits set for autoscaling (minimum or maximum) are set in terms of Instance Count.
The manually set scale for instance count and the minimum instance count in autoscale config will reserve 10
capacity units/instance. These reserved CUs will be billed as long as the Application Gateway is active regardless
of the actual resource consumption. If actual consumption crosses the 10 capacity units/instance threshold,
additional capacity units will be billed under the variable component.
V2 SKUs are billed based on the consumption and constitute of two parts:
Fixed Costs
Cost based on the time the Application Gateway V2 /WAF V2 is provisioned and available for processing
requests. This ensures high availability - even if 0 instances are reserved by specifying 0 in minimum
instance count as part of autoscaling.
The fixed cost also includes the cost associated with the public IP attached to the Application Gateway.
The number of instances running at any point of time is not considered as a factor for fixed costs for V2
SKUs. The fixed costs of running a Standard_V2 (or WAF_V2) would be same per hour regardless of the
number of instances running within the same Azure region.
Capacity Unit Costs
Cost based on the number of capacity units either reserved or utilized additionally as required for
processing the incoming requests. Consumption based costs are computed hourly.
Total Costs = Fixed Costs + Capacity Unit Costs
NOTE
A partial hour is billed as a full hour.
The following table shows example prices based on a snapshot of East US pricing and are for illustration
purposes only.
Fixed Costs (East US region pricing)
V2 SK U C O ST S ( $/ H R)
Standard_V2 $0.246
WAF_V2 $0.443
Monthly price estimates are based on 730 hours of usage per month.
Variable Costs (East US region pricing)
1 CU $0.008 $0.0144
For more pricing information according to your region, see the pricing page.
NOTE
Outbound data transfers - data going out of Azure data centers from application gateways will be charged at standard
data transfer rates.
NOTE
Actual Traffic observed for your Application Gateway is unlikely to have such a constant pattern of traffic and the
observed load on your Application Gateway would fluctuate according to actual usage.
Example 3 (a) – WAF_V2 instance with Autoscaling and 0 Min scale config
Let’s assume you’ve provisioned a WAF_V2 with autoscaling enabled and set the minimum instance count as 0
for the entire month. The request load on the WAF is minimum but consistently present per hour for the entire
month. The load is below the capacity of a single capacity unit. Your Application Gateway costs using the pricing
mentioned above would be calculated as follows:
Monthly price estimates are based on 730 hours of usage per month.
Fixed Price = $0.443 * 730 (Hours) = $323.39
Variable Costs = $0.0144 * 1(capacity units) * 730 (Hours) = $10.512
Total Costs = $323.39 + $10.512 = $333.902
Example 3 (b) – WAF_V2 instance with Autoscaling with 0 Min instance count
Let’s assume you’ve provisioned a WAF_V2 with autoscaling enabled and set the minimum instance count to 0
for the entire month. However, there is 0 traffic directed to the WAF instance for the entire month. Your
Application Gateway costs using the pricing mentioned above would be calculated as follows:
Fixed Price = $0.443 * 730 (Hours) = $323.39
Variable Costs = $0.0144 * 0(capacity units) * 730 (Hours) = $0
Total Costs = $323.39 + $0 = $323.39
Example 3 (C ) – WAF_V2 instance with manual scaling set to 1 instance
Let’s assume you’ve provisioned a WAF_V2 and set it to manual scaling with the minimum acceptable value of 1
instance for the entire month. However, there is 0 traffic directed to the WAF for the entire month. Your
Application Gateway costs using the pricing mentioned above would be calculated as follows:
Monthly price estimates are based on 730 hours of usage per month.
Fixed Price = $0.443 * 730 (Hours) = $323.39
Variable Costs = $0.0144 * 1(Instance count) * 10(capacity units) * 730 (Hours) = $105.12
Total Costs = $323.39 + $105.12 = $428.51
Example 4 – WAF_V2 with Autoscaling, capacity unit calculations
Let’s assume you’ve provisioned a WAF_V2 with autoscaling enabled and set the minimum instance count to 0
for the entire month. During this time, it receives 25 new TLS connections/sec with an average of 8.88-Mbps
data transfer. Your Application Gateway costs using the pricing mentioned above would be calculated as follows:
Monthly price estimates are based on 730 hours of usage per month.
Fixed Price = $0.443 * 730 (Hours) = $323.39
Variable Costs = $0.0144 * 730 (Hours) * {Max (25/50, 8.88/2.22)} = $23.36 (4 Capacity units required to handle
8.88 Mbps)
Total Costs = $323.39 + $23.36 = $346.75
Example 5 (a) – Standard_V2 with Autoscaling, time -based calculations
Let’s assume you’ve provisioned a standard_V2 with autoscaling enabled and set the minimum instance count
to 0 and this application gateway is active for 2 hours. During the first hour, it receives traffic that can be handled
by 10 Capacity Units and during the second hour it receives traffic that required 20 Capacity Units to handle the
load. Your Application Gateway costs using the pricing mentioned above would be calculated as follows:
Fixed Price = $0.246 * 2 (Hours) = $0.492
Variable Costs = $0.008 * 10(capacity units) * 1 (Hours) + $0.008 * 20(capacity units) * 1 (Hours) = $0.24
Total Costs = $0.492 + $0.24 = $0.732
Monitoring Billed Usage
You can view the amount of consumption for different parameters (compute unit, throughput & persistent
connections) as well as the Capacity Units being utilized as part of the Application Gateway metrics under the
Monitoring section.
Useful metrics for cost estimation
Current capacity units
Count of capacity units consumed to load balance the traffic across the three parameters - Current
connections, Throughput and Compute unit
Fixed Billable Capacity Units
The minimum number of capacity units kept provisioned as per the minimum instance count setting (one
instance translates to 10 capacity units) in the Application Gateway configuration.
Estimated Billed Capacity units
Estimated Billed Capacity units indicates the number of capacity units using which the billing is estimated.
This is calculated as the greater value between Current capacity units (capacity units required to load
balance the traffic) and Fixed billable capacity units (minimum capacity units kept provisioned).
More metrics such as throughput, current connections and compute units are also available to understand
bottlenecks and estimate the number of capacity units required. Detailed information is available at Application
Gateway Metrics
Example - Estimating Capacity Units being utilized
Obser ved Metrics:
Compute Units = 17.38
Throughput = 1.37M Bytes/sec - 10.96 Mbps
Current Connections = 123.08k
Capacity Units calculated = max(17.38, 10.96/2.22, 123.08k/2500) = 49.232
Observed Capacity Units in metrics = 49.23
Next steps
See the following articles to learn more about how pricing works in Azure Application Gateway:
Azure Application Gateway pricing page
Azure Application Gateway pricing calculator
Manage web traffic with an application gateway
using Azure PowerShell
3/5/2021 • 6 minutes to read • Edit Online
Application gateway is used to manage and secure web traffic to servers that you maintain. You can use Azure
PowerShell to create an application gateway that uses a virtual machine scale set for backend servers to manage
web traffic. In this example, the scale set contains two virtual machine instances that are added to the default
backend pool of the application gateway.
In this article, you learn how to:
Set up the network
Create an application gateway
Create a virtual machine scale set with the default backend pool
If you prefer, you can complete this procedure using Azure CLI.
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
O P T IO N EXA M P L E/ L IN K
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.1.0/24
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Static `
-Sku Standard
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$subnet=$vnet.Subnets[1]
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 80
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $defaultPool `
-BackendHttpSettings $poolSettings
$sku = New-AzApplicationGatewaySku `
-Name Standard_v2 `
-Tier Standard_v2 `
-Capacity 2
$appgw = New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $defaultPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$backendPool = Get-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool `
-ApplicationGateway $appgw
$ipConfig = New-AzVmssIpConfig `
-Name myVmssIPConfig `
-SubnetId $vnet.Subnets[0].Id `
-ApplicationGatewayBackendAddressPoolsId $backendPool.Id
$vmssConfig = New-AzVmssConfig `
-Location eastus `
-SkuCapacity 2 `
-SkuName Standard_DS2_v2 `
-UpgradePolicyMode Automatic
Set-AzVmssStorageProfile $vmssConfig `
-ImageReferencePublisher MicrosoftWindowsServer `
-ImageReferenceOffer WindowsServer `
-ImageReferenceSku 2016-Datacenter `
-ImageReferenceVersion latest `
-OsDiskCreateOption FromImage
Set-AzVmssOsProfile $vmssConfig `
-AdminUsername azureuser `
-AdminPassword "Azure123456!" `
-ComputerNamePrefix myvmss
Add-AzVmssNetworkInterfaceConfiguration `
-VirtualMachineScaleSet $vmssConfig `
-Name myVmssNetConfig `
-Primary $true `
-IPConfiguration $ipConfig
New-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss `
-VirtualMachineScaleSet $vmssConfig
Install IIS
Update-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss `
-VirtualMachineScaleSet $vmss
Test the application gateway
Use Get-AzPublicIPAddress to get the public IP address of the application gateway. Copy the public IP address,
and then paste it into the address bar of your browser.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Next steps
Restrict web traffic with a web application firewall
Manage web traffic with an application gateway
using the Azure CLI
3/5/2021 • 3 minutes to read • Edit Online
Application gateway is used to manage and secure web traffic to servers that you maintain. You can use the
Azure CLI to create an application gateway that uses a virtual machine scale set for backend servers. In this
example, the scale set contains two virtual machine instances. The scale set is added to the default backend pool
of the application gateway.
In this article, you learn how to:
Set up the network
Create an application gateway
Create a virtual machine scale set with the default backend pool
If you prefer, you can complete this procedure using Azure PowerShell.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you'll see these new features:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
az vmss create \
--name myvmss \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name appGatewayBackendPool
Install NGINX
Now you can install NGINX on the virtual machine scale set so you can test HTTP connectivity to the backend
pool.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources.
Next steps
Restrict web traffic with a web application firewall
Configure an application gateway with an internal
load balancer (ILB) endpoint
3/5/2021 • 5 minutes to read • Edit Online
Azure Application Gateway can be configured with an Internet-facing VIP or with an internal endpoint that isn't
exposed to the Internet. An internal endpoint uses a private IP address for the frontend, which is also known as
an internal load balancer (ILB) endpoint.
Configuring the gateway using a frontend private IP address is useful for internal line-of-business applications
that aren't exposed to the Internet. It's also useful for services and tiers within a multi-tier application that are in
a security boundary that isn't exposed to the Internet but:
still require round-robin load distribution
session stickiness
or Transport Layer Security (TLS) termination (previously known as Secure Sockets Layer (SSL)).
This article guides you through the steps to configure an application gateway with a frontend private IP address
using the Azure portal.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Sign in to Azure
Sign in to the Azure portal at https://portal.azure.com
NOTE
Once allocated, the IP address type (static or dynamic) cannot be changed later.
Set-AzVMExtension `
-ResourceGroupName myResourceGroupAG `
-ExtensionName IIS `
-VMName myVM `
-Publisher Microsoft.Compute `
-ExtensionType CustomScriptExtension `
-TypeHandlerVersion 1.4 `
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-
Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
-Location CentralUS
3. Create a second virtual machine and install IIS using the steps that you just finished. Use myVM2 for the
virtual machine name and for VMName in Set-AzVMExtension .
Add backend servers to backend pool
1. Select All resources , and then select myAppGateway .
2. Select Backend pools , and then select appGatewayBackendPool .
3. Under Target type select Vir tual machine and under Target , select the vNIC associated with myVM.
4. Repeat to add MyVM2.
5. Select Save.
2. Copy the private IP address, and then paste it into the browser address bar on myVM3 to access the
application gateway backend pool.
Next steps
If you want to monitor the health of your backend pool, see Back-end health and diagnostic logs for Application
Gateway.
Create an application gateway with an internal load
balancer (ILB)
3/5/2021 • 7 minutes to read • Edit Online
Azure Application Gateway can be configured with an Internet-facing VIP or with an internal endpoint that is not
exposed to the Internet, also known as an internal load balancer (ILB) endpoint. Configuring the gateway with an
ILB is useful for internal line-of-business applications that are not exposed to the Internet. It's also useful for
services and tiers within a multi-tier application that sit in a security boundary that is not exposed to the Internet
but still require round-robin load distribution, session stickiness, or Transport Layer Security (TLS), previously
known as Secure Sockets Layer (SSL), termination.
This article walks you through the steps to configure an application gateway with an ILB.
1. Install the latest version of the Azure PowerShell module by following the install instructions.
2. You create a virtual network and a subnet for Application Gateway. Make sure that no virtual machines or
cloud deployments are using the subnet. Application Gateway must be by itself in a virtual network subnet.
3. The servers that you configure to use the application gateway must exist or have their endpoints created
either in the virtual network or with a public IP/VIP assigned.
Connect-AzAccount
Step 2
Check the subscriptions for the account.
Get-AzSubscription
Step 4
Create a new resource group (skip this step if you're using an existing resource group).
Azure Resource Manager requires that all resource groups specify a location. This is used as the default location
for resources in that resource group. Make sure that all commands to create an application gateway uses the
same resource group.
In the preceding example, we created a resource group called "appgw-rg" and location "West US".
This step assigns the address range 10.0.0.0/24 to a subnet variable to be used to create a virtual network.
Step 2
$vnet = New-AzVirtualNetwork -Name appgwvnet -ResourceGroupName appgw-rg -Location "West US" -AddressPrefix
10.0.0.0/16 -Subnet $subnetconfig
This step creates a virtual network named "appgwvnet" in resource group "appgw-rg" for the West US region
using the prefix 10.0.0.0/16 with subnet 10.0.0.0/24.
Step 3
$subnet = $vnet.subnets[0]
This step assigns the subnet object to variable $subnet for the next steps.
This step creates an application gateway IP configuration named "gatewayIP01". When Application Gateway
starts, it picks up an IP address from the subnet configured and route network traffic to the IP addresses in the
back-end IP pool. Keep in mind that each instance takes one IP address.
Step 2
This step configures the back-end IP address pool named "pool01" with IP addresses "10.1.1.8, 10.1.1.9,
10.1.1.10". Those are the IP addresses that receive the network traffic that comes from the front-end IP endpoint.
You replace the preceding IP addresses to add your own application IP address endpoints.
Step 3
This step configures application gateway setting "poolsetting01" for the load balanced network traffic in the
back-end pool.
Step 4
This step configures the front-end IP port named "frontendport01" for the ILB.
Step 5
This step creates the front-end IP configuration called "fipconfig01" and associates it with a private IP from the
current virtual network subnet.
Step 6
$listener = New-AzApplicationGatewayHttpListener -Name listener01 -Protocol Http -FrontendIPConfiguration
$fipconfig -FrontendPort $fp
This step creates the listener called "listener01" and associates the front-end port to the front-end IP
configuration.
Step 7
This step creates the load balancer routing rule called "rule01" that configures the load balancer behavior.
Step 8
NOTE
The default value for Capacity is 2. For Sku Name, you can choose between Standard_Small, Standard_Medium, and
Standard_Large.
This step creates an application gateway with all configuration items from the preceding steps. In the example,
the application gateway is called "appgwtest".
Step 2
Use Stop-AzApplicationGateway to stop the application gateway. This sample shows the
Stop-AzApplicationGateway cmdlet on the first line, followed by the output.
Once the application gateway is in a stopped state, use the Remove-AzApplicationGateway cmdlet to remove the
service.
NOTE
The -force switch can be used to suppress the remove confirmation message.
To verify that the service has been removed, you can use the Get-AzApplicationGateway cmdlet. This step is not
required.
Next steps
If you want to configure SSL offload, see Configure an application gateway for SSL offload.
If you want more information about load balancing options in general, see:
Azure Load Balancer
Azure Traffic Manager
Create an application gateway with TLS termination
using Azure PowerShell
3/5/2021 • 5 minutes to read • Edit Online
You can use Azure PowerShell to create an application gateway with a certificate for TLS/SSL termination that
uses a virtual machine scale set for backend servers. In this example, the scale set contains two virtual machine
instances that are added to the default backend pool of the application gateway.
In this article, you learn how to:
Create a self-signed certificate
Set up a network
Create an application gateway with the certificate
Create a virtual machine scale set with the default backend pool
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This article requires the Azure PowerShell module version 1.0.0 or later. Run Get-Module -ListAvailable Az to
find the version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell
locally, you also need to run Login-AzAccount to create a connection with Azure.
New-SelfSignedCertificate `
-certstorelocation cert:\localmachine\my `
-dnsname www.contoso.com
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
Thumbprint Subject
---------- -------
E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 CN=www.contoso.com
Export-PfxCertificate `
-cert cert:\localMachine\my\E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 `
-FilePath c:\appgwcert.pfx `
-Password $pwd
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.1.0/24
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Static `
-Sku Standard
$subnet=$vnet.Subnets[0]
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 443
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$cert = New-AzApplicationGatewaySslCertificate `
-Name "appgwcert" `
-CertificateFile "c:\appgwcert.pfx" `
-Password $pwd
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name mydefaultListener `
-Protocol Https `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport `
-SslCertificate $cert
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $defaultPool `
-BackendHttpSettings $poolSettings
$sku = New-AzApplicationGatewaySku `
-Name Standard_v2 `
-Tier Standard_v2 `
-Capacity 2
$appgw = New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $defaultPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku `
-SslCertificates $cert
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$backendPool = Get-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool `
-ApplicationGateway $appgw
$ipConfig = New-AzVmssIpConfig `
-Name myVmssIPConfig `
-SubnetId $vnet.Subnets[1].Id `
-ApplicationGatewayBackendAddressPoolsId $backendPool.Id
$vmssConfig = New-AzVmssConfig `
-Location eastus `
-SkuCapacity 2 `
-SkuName Standard_DS2 `
-UpgradePolicyMode Automatic
Set-AzVmssStorageProfile $vmssConfig `
-ImageReferencePublisher MicrosoftWindowsServer `
-ImageReferenceOffer WindowsServer `
-ImageReferenceSku 2016-Datacenter `
-ImageReferenceVersion latest `
-OsDiskCreateOption FromImage
Set-AzVmssOsProfile $vmssConfig `
-AdminUsername azureuser `
-AdminPassword "Azure123456!" `
-ComputerNamePrefix myvmss
Add-AzVmssNetworkInterfaceConfiguration `
-VirtualMachineScaleSet $vmssConfig `
-Name myVmssNetConfig `
-Primary $true `
-IPConfiguration $ipConfig
New-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss `
-VirtualMachineScaleSet $vmssConfig
Install IIS
Update-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss `
-VirtualMachineScaleSet $vmss
Test the application gateway
You can use Get-AzPublicIPAddress to get the public IP address of the application gateway. Copy the public IP
address, and then paste it into the address bar of your browser.
To accept the security warning if you used a self-signed certificate, select Details and then Go on to the
webpage . Your secured IIS website is then displayed as in the following example:
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Next steps
Create an application gateway that hosts multiple web sites
Create an application gateway with TLS termination
using the Azure CLI
4/2/2021 • 4 minutes to read • Edit Online
You can use the Azure CLI to create an application gateway with a certificate for TLS termination. For backend
servers, you can use a virtual machine scale set. In this example, the scale set contains two virtual machine
instances that are added to the default backend pool of the application gateway.
In this article, you learn how to:
Create a self-signed certificate
Set up a network
Create an application gateway with the certificate
Create a virtual machine scale set with the default backend pool
If you prefer, you can complete this procedure using Azure PowerShell.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out appgwcert.crt
Enter values that make sense for your certificate. You can accept the default values.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features of it:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
az vmss create \
--name myvmss \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name appGatewayBackendPool
Install NGINX
Copy the public IP address, and then paste it into the address bar of your browser. For this example, the URL is:
https://52.170.203.149 .
To accept the security warning if you used a self-signed certificate, select Details and then Go on to the
webpage . Your secured NGINX site is then displayed as in the following example:
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources.
Azure Key Vault is a platform-managed secret store that you can use to safeguard secrets, keys, and TLS/SSL
certificates. Azure Application Gateway supports integration with Key Vault for server certificates that are
attached to HTTPS-enabled listeners. This support is limited to the Application Gateway v2 SKU.
For more information, see TLS termination with Key Vault certificates.
This article shows you how to use an Azure PowerShell script to integrate your key vault with your application
gateway for TLS/SSL termination certificates.
This article requires Azure PowerShell module version 1.0.0 or later. To find the version, run
Get-Module -ListAvailable Az . If you need to upgrade, see Install Azure PowerShell module. To run the
commands in this article, you also need to create a connection with Azure by running Connect-AzAccount .
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Before you begin, you must have the ManagedServiceIdentity module installed:
Example script
Set up variables
$rgname = "KeyVaultTest"
$location = "East US"
$kv = "<your key vault name>"
$appgwName = "AppGwKVIntegration"
IMPORTANT
The key vault name must be universally unique.
Create a key vault, policy, and certificate to be used by the application gateway
$keyVault = New-AzKeyVault -Name $kv -ResourceGroupName $rgname -Location $location -EnableSoftDelete
Set-AzKeyVaultAccessPolicy -VaultName $kv -PermissionsToSecrets get -ObjectId $identity.PrincipalId
NOTE
The -EnableSoftDelete flag must be used for TLS termination to function properly. If you're configuring Key Vault soft-
delete through the Portal, the retention period must be kept at 90 days, the default value. Application Gateway doesn't
support a different retention period yet.
Next steps
Learn more about TLS termination
Configure end-to-end TLS by using Application
Gateway with the portal
3/5/2021 • 4 minutes to read • Edit Online
This article describes how to use the Azure portal to configure end-to-end Transport Layer Security (TLS)
encryption, previously known as Secure Sockets Layer (SSL) encryption, through Azure Application Gateway v1
SKU.
NOTE
Application Gateway v2 SKU requires trusted root certificates for enabling end-to-end configuration.
If you don't have an Azure subscription, create a free account before you begin.
For Standard_v2 and WAF_v2 application gateways, you should upload the root certificate of the back-
end server certificate in .cer format. If the back-end certificate is issued by a well-known certificate
authority (CA), you can select the Use Well Known CA Cer tificate check box, and then you don't have
to upload a certificate.
8. Select Save .
6. Add other required settings for the Listener , depending on your requirements.
7. Select OK to save.
Add authentication/trusted root certificates of back-end servers
1. Select All resources , and then select myAppGateway .
2. Select HTTP settings from the left-side menu. You can either put certificates in an existing back-end
HTTP setting on the Safe Recipients list or create a new HTTP setting. (In the next step, the certificate for
the default HTTP setting, appGatewayBackendHttpSettings , is added to the Safe Recipients list.)
3. Select appGatewayBackendHttpSettings .
4. Under Protocol , select HTTPS . A pane for Backend authentication cer tificates or Trusted root
cer tificates appears.
5. Select Create new .
6. In the Name field, enter a suitable name.
7. Select the certificate file in the Upload CER cer tificate box.
For Standard and WAF (v1) application gateways, you should upload the public key of your back-end
server certificate in .cer format.
For Standard_v2 and WAF_v2 application gateways, you should upload the root certificate of the back-
end server certificate in .cer format. If the back-end certificate is issued by a well-known CA, you can
select the Use Well Known CA Cer tificate check box, and then you don't have to upload a certificate.
8. Select Save .
Next steps
Manage web traffic with an application gateway using the Azure CLI
Configure end to end TLS by using Application
Gateway with PowerShell
3/5/2021 • 11 minutes to read • Edit Online
Overview
Azure Application Gateway supports end-to-end encryption of traffic. Application Gateway terminates the
TLS/SSL connection at the application gateway. The gateway then applies the routing rules to the traffic, re-
encrypts the packet, and forwards the packet to the appropriate back-end server based on the routing rules
defined. Any response from the web server goes through the same process back to the end user.
Application Gateway supports defining custom TLS options. It also supports disabling the following protocol
versions: TLSv1.0 , TLSv1.1 , and TLSv1.2 , as well defining which cipher suites to use and the order of
preference. To learn more about configurable TLS options, see the TLS policy overview.
NOTE
SSL 2.0 and SSL 3.0 are disabled by default and cannot be enabled. They are considered unsecure and cannot be used
with Application Gateway.
Scenario
In this scenario, you learn how to create an application gateway by using end-to-end TLS with PowerShell.
This scenario will:
Create a resource group named appgw-rg .
Create a virtual network named appgwvnet with an address space of 10.0.0.0/16 .
Create two subnets called appgwsubnet and appsubnet .
Create a small application gateway supporting end-to-end TLS encryption that limits TLS protocol versions
and cipher suites.
To configure end-to-end TLS with an application gateway, a certificate is required for the gateway and
certificates are required for the back-end servers. The gateway certificate is used to derive a symmetric key as
per TLS protocol specification. The symmetric key is then used encrypt and decrypt the traffic sent to the
gateway. The gateway certificate needs to be in Personal Information Exchange (PFX) format. This file format
allows you to export the private key that is required by the application gateway to perform the encryption and
decryption of traffic.
For end-to-end TLS encryption, the back end must be explicitly allowed by the application gateway. Upload the
public certificate of the back-end servers to the application gateway. Adding the certificate ensures that the
application gateway only communicates with known back-end instances. This further secures the end-to-end
communication.
The configuration process is described in the following sections.
Connect-AzAccount
3. Create a resource group. (Skip this step if you're using an existing resource group.)
3. Create a virtual network with the subnets defined in the preceding steps.
4. Retrieve the virtual network resource and subnet resources to be used in the steps that follow.
IMPORTANT
Application Gateway does not support the use of a public IP address created with a defined domain label. Only a public IP
address with a dynamically created domain label is supported. If you require a friendly DNS name for the application
gateway, we recommend you use a CNAME record as an alias.
2. Create a front-end IP configuration. This setting maps a private or public IP address to the front end of the
application gateway. The following step associates the public IP address in the preceding step with the
front-end IP configuration.
$fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name 'fip01' -PublicIPAddress $publicip
3. Configure the back-end IP address pool with the IP addresses of the back-end web servers. These IP
addresses are the IP addresses that receive the network traffic that comes from the front-end IP endpoint.
Replace the IP addresses in the sample with your own application IP address endpoints.
NOTE
A fully qualified domain name (FQDN) is also a valid value to use in place of an IP address for the back-end
servers. You enable it by using the -BackendFqdns switch.
4. Configure the front-end IP port for the public IP endpoint. This port is the port that end users connect to.
5. Configure the certificate for the application gateway. This certificate is used to decrypt and reencrypt the
traffic on the application gateway.
NOTE
This sample configures the certificate used for the TLS connection. The certificate needs to be in .pfx format, and
the password must be 4 to 12 characters.
6. Create the HTTP listener for the application gateway. Assign the front-end IP configuration, port, and
TLS/SSL certificate to use.
NOTE
The default probe gets the public key from the default TLS binding on the back-end's IP address and compares the
public key value it receives to the public key value you provide here.
If you are using host headers and Server Name Indication (SNI) on the back end, the retrieved public key might
not be the intended site to which traffic flows. If you're in doubt, visit https://127.0.0.1/ on the back-end servers
to confirm which certificate is used for the default TLS binding. Use the public key from that request in this
section. If you are using host-headers and SNI on HTTPS bindings and you do not receive a response and
certificate from a manual browser request to https://127.0.0.1/ on the back-end servers, you must set up a
default TLS binding on the them. If you do not do so, probes fail and the back end is not allowed.
For more information about SNI in Application Gateway, see Overview of TLS termination and end to end
TLS with Application Gateway.
NOTE
The certificate provided in the previous step should be the public key of the .pfx certificate present on the back
end. Export the certificate (not the root certificate) installed on the back-end server in Claim, Evidence, and
Reasoning (CER) format and use it in this step. This step allows the back end with the application gateway.
If you are using the Application Gateway v2 SKU, then create a trusted root certificate instead of an
authentication certificate. For more information, see Overview of end to end TLS with Application
Gateway:
8. Configure the HTTP settings for the application gateway back end. Assign the certificate uploaded in the
preceding step to the HTTP settings.
9. Create a load-balancer routing rule that configures the load balancer behavior. In this example, a basic
round-robin rule is created.
10. Configure the instance size of the application gateway. The available sizes are Standard_Small ,
Standard_Medium , and Standard_Large . For capacity, the available values are 1 through 10 .
NOTE
An instance count of 1 can be chosen for testing purposes. It is important to know that any instance count under
two instances is not covered by the SLA and is therefore not recommended. Small gateways are to be used for
dev test and not for production purposes.
11. Configure the TLS policy to be used on the application gateway. Application Gateway supports the ability
to set a minimum version for TLS protocol versions.
The following values are a list of protocol versions that can be defined:
TLSV1_0
TLSV1_1
TLSV1_2
The following example sets the minimum protocol version to TLSv1_2 and enables
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 , and
TLS_RSA_WITH_AES_128_GCM_SHA256 only.
2. Add the new certificate resource from the .cer file, which contains the public key of the certificate and can
also be the same certificate added to the listener for TLS termination at the application gateway.
4. Assign the new certificate into the BackendHttp Setting and refer it with the $AuthCert variable. (Specify
the HTTP setting name that you want to change.)
5. Commit the change into the application gateway and pass the new configuration contained into the $out
variable.
2. List the name of the authentication certificate that you want to remove.
2. Define a TLS policy. In the following example, TLSv1.0 and TLSv1.1 are disabled and the cipher suites
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 , and
TLS_RSA_WITH_AES_128_GCM_SHA256 are the only ones allowed.
Set-AzApplicationGatewaySSLPolicy -MinProtocolVersion TLSv1_2 -PolicyType Custom -CipherSuite
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"TLS_RSA_WITH_AES_128_GCM_SHA256" -ApplicationGateway $gw
3. Finally, update the gateway. This last step is a long-running task. When it is done, end-to-end TLS is
configured on the application gateway.
$gw | Set-AzApplicationGateway
Name : publicIP01
ResourceGroupName : appgw-RG
Location : westus
Id : /subscriptions/<subscription_id>/resourceGroups/appgw-
RG/providers/Microsoft.Network/publicIPAddresses/publicIP01
Etag : W/"00000d5b-54ed-4907-bae8-99bd5766d0e5"
ResourceGuid : 00000000-0000-0000-0000-000000000000
ProvisioningState : Succeeded
Tags :
PublicIpAllocationMethod : Dynamic
IpAddress : xx.xx.xxx.xx
PublicIpAddressVersion : IPv4
IdleTimeoutInMinutes : 4
IpConfiguration : {
"Id": "/subscriptions/<subscription_id>/resourceGroups/appgw-
RG/providers/Microsoft.Network/applicationGateways/appgwtest/frontendIP
Configurations/frontend1"
}
DnsSettings : {
"Fqdn": "00000000-0000-xxxx-xxxx-xxxxxxxxxxxx.cloudapp.net"
}
Next steps
For more information about hardening the security of your web applications with Web Application Firewall
through Application Gateway, see the Web application firewall overview.
Configure mutual authentication with Application
Gateway through portal (Preview)
4/2/2021 • 3 minutes to read • Edit Online
This article describes how to use the Azure portal to configure mutual authentication on your Application
Gateway. Mutual authentication means Application Gateway authenticates the client sending the request using
the client certificate you upload onto the Application Gateway.
If you don't have an Azure subscription, create a free account before you begin.
IMPORTANT
Please ensure that you upload the entire client CA certificate chain in one file, and only one chain per file.
1. Search for Application Gateway in portal, select Application gateways , and click on your existing
Application Gateway.
2. Select SSL settings (Preview) from the left-side menu.
3. Click on the plus sign next to SSL Profiles at the top to create a new SSL profile.
4. Enter a name under SSL Profile Name . In this example, we call our SSL profile
applicationGatewaySSLProfile.
5. Stay in the Client Authentication tab. Upload the PEM certificate you intend to use for mutual
authentication between the client and the Application Gateway using the Upload a new cer tificate
button.
For more information on how to extract trusted client CA certificate chains to upload here, see how to
extract trusted client CA certificate chains.
NOTE
If this isn't your first SSL profile and you've uploaded other client certificates onto your Application Gateway, you
can choose to reuse an existing certificate on your gateway through the dropdown menu.
6. Check the Verify client cer tificate issuer's DN box only if you want Application Gateway to verify the
client certificate's immediate issuer Distinguished Name.
7. Consider adding a listener specific policy. See instructions at setting up listener specific SSL policies.
8. Select Add to save.
Next steps
Manage web traffic with an application gateway using the Azure CLI
Configure mutual authentication with Application
Gateway through PowerShell (Preview)
4/2/2021 • 4 minutes to read • Edit Online
This article describes how to use the PowerShell to configure mutual authentication on your Application
Gateway. Mutual authentication means Application Gateway authenticates the client sending the request using
the client certificate you upload onto the Application Gateway.
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This article requires the Azure PowerShell module version 1.0.0 or later. Run Get-Module -ListAvailable Az to
find the version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell
locally, you also need to run Login-AzAccount to create a connection with Azure.
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}
Create a public IP
Create a public IP to use with your Application Gateway.
IMPORTANT
Please ensure that you upload the entire client CA certificate chain in one file, and only one chain per file.
NOTE
We recommend using TLS 1.2 with mutual authentication as TLS 1.2 will be mandated in the future.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Connect-AzAccount
Select-AzSubscription -Subscription "<sub name>"
2. Get your Application Gateway configuration
Next steps
Manage web traffic with an application gateway using the Azure CLI
Create certificates to allow the backend with Azure
Application Gateway
3/5/2021 • 3 minutes to read • Edit Online
To do end to end TLS, Application Gateway requires the backend instances to be allowed by uploading
authentication/trusted root certificates. For the v1 SKU, authentication certificates are required, but for the v2
SKU trusted root certificates are required to allow the certificates.
In this article, you learn how to:
Export authentication certificate from a backend certificate (for v1 SKU)
Export trusted root certificate from a backend certificate (for v2 SKU)
Prerequisites
An existing backend certificate is required to generate the authentication certificates or trusted root certificates
required for allowing backend instances with Application Gateway. The backend certificate can be the same as
the TLS/SSL certificate or different for added security. Application Gateway doesn't provide you any mechanism
to create or purchase an TLS/SSL certificate. For testing purposes, you can create a self-signed certificate but
you shouldn't use it for production workloads.
3. Select No, do not expor t the private key , and then click Next .
4. On the Expor t File Format page, select Base-64 encoded X.509 (.CER)., and then click Next .
5. For File to Expor t , Browse to the location to which you want to export the certificate. For File name ,
name the certificate file. Then, click Next .
8. If you open the exported certificate using Notepad, you see something similar to this example. The
section in blue contains the information that is uploaded to application gateway. If you open your
certificate with Notepad and it doesn't look similar to this, typically this means you didn't export it using
the Base-64 encoded X.509(.CER) format. Additionally, if you want to use a different text editor,
understand that some editors can introduce unintended formatting in the background. This can create
problems when uploaded the text from this certificate to Azure.
6. At this point, you've extracted the details of the root certificate from the backend certificate. You'll see the
Cer tificate Expor t Wizard . Now use steps 2-9 mentioned in the section Expor t authentication
cer tificate from a backend cer tificate (for v1 SKU) above to export the trusted root certificate in
the Base-64 encoded X.509(.CER) format.
Next steps
Now you have the authentication certificate/trusted root certificate in Base-64 encoded X.509(.CER) format. You
can add this to the application gateway to allow your backend servers for end to end TLS encryption. See
Configure end to end TLS by using Application Gateway with PowerShell.
Renew Application Gateway certificates
3/5/2021 • 2 minutes to read • Edit Online
At some point, you'll need to renew your certificates if you configured your application gateway for TLS/SSL
encryption.
You can renew a certificate associated with a listener using either the Azure portal, Azure PowerShell, or Azure
CLI:
Azure portal
To renew a listener certificate from the portal, navigate to your application gateway listeners. Select the listener
that has a certificate that needs to be renewed, and then select Renew or edit selected cer tificate .
Upload your new PFX certificate, give it a name, type the password, and then select Save .
Azure PowerShell
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
To renew your certificate using Azure PowerShell, use the following script:
$appgw = Get-AzApplicationGateway `
-ResourceGroupName <ResourceGroup> `
-Name <AppGatewayName>
$password = ConvertTo-SecureString `
-String "<password>" `
-Force `
-AsPlainText
Azure CLI
az network application-gateway ssl-cert update \
-n "<CertName>" \
--gateway-name "<AppGatewayName>" \
-g "ResourceGroupName>" \
--cert-file <PathToCerFile> \
--cert-password "<password>"
Next steps
To learn how to configure TLS Offloading with Azure Application Gateway, see Configure TLS Offload
Generate an Azure Application Gateway self-signed
certificate with a custom root CA
3/5/2021 • 6 minutes to read • Edit Online
The Application Gateway v2 SKU introduces the use of Trusted Root Certificates to allow backend servers. This
removes authentication certificates that were required in the v1 SKU. The root certificate is a Base-64 encoded
X.509(.CER) format root certificate from the backend certificate server. It identifies the root certificate authority
(CA) that issued the server certificate and the server certificate is then used for the TLS/SSL communication.
Application Gateway trusts your website's certificate by default if it's signed by a well-known CA (for example,
GoDaddy or DigiCert). You don't need to explicitly upload the root certificate in that case. For more information,
see Overview of TLS termination and end to end TLS with Application Gateway. However, if you have a dev/test
environment and don't want to purchase a verified CA signed certificate, you can create your own custom CA
and create a self-signed certificate with it.
NOTE
Self-signed certificates are not trusted by default and they can be difficult to maintain. Also, they may use outdated hash
and cipher suites that may not be strong. For better security, purchase a certificate signed by a well-known certificate
authority.
Prerequisites
OpenSSL on a computer running Windows or Linux
While there could be other tools available for certificate management, this tutorial uses OpenSSL. You can
find OpenSSL bundled with many Linux distributions, such as Ubuntu.
A web ser ver
For example, Apache, IIS, or NGINX to test the certificates.
An Application Gateway v2 SKU
If you don't have an existing application gateway, see Quickstart: Direct web traffic with Azure Application
Gateway - Azure portal.
2. At the prompt, type a strong password. For example, at least nine characters, using upper case, lower
case, numbers, and symbols.
Create a Root Certificate and self-sign it
1. Use the following commands to generate the csr and the certificate.
openssl x509 -req -sha256 -days 365 -in contoso.csr -signkey contoso.key -out contoso.crt
The previous commands create the root certificate. You'll use this to sign your server certificate.
2. When prompted, type the password for the root key, and the organizational information for the custom
CA such as Country/Region, State, Org, OU, and the fully qualified domain name (this is the domain of the
issuer).
NOTE
The CN (Common Name) for the server certificate must be different from the issuer's domain. For example, in this case,
the CN for the issuer is www.contoso.com and the server certificate's CN is www.fabrikam.com .
Generate the certificate with the CSR and the key and sign it with the CA's root key
1. Use the following command to create the certificate:
openssl x509 -req -in fabrikam.csr -CA contoso.crt -CAkey contoso.key -CAcreateserial -out
fabrikam.crt -days 365 -sha256
2. Verify the files in your directory, and ensure you have the following files:
contoso.crt
contoso.key
fabrikam.crt
fabrikam.key
<VirtualHost www.fabrikam:443>
DocumentRoot /var/www/fabrikam
ServerName www.fabrikam.com
SSLEngine on
SSLCertificateFile /home/user/fabrikam.crt
SSLCertificateKeyFile /home/user/fabrikam.key
</VirtualHost>
NGINX
The following configuration is an example NGINX server block with TLS configuration:
NOTE
It's assumed that DNS has been configured to point the web server name (in this example, www.fabrikam.com) to
your web server's IP address. If not, you can edit the hosts file to resolve the name.
2. Browse to your website, and click the lock icon on your browser's address box to verify the site and
certificate information.
Azure PowerShell
Or, you can use Azure CLI or Azure PowerShell to upload the root certificate. The following code is an Azure
PowerShell sample.
NOTE
The following sample adds a trusted root certificate to the application gateway, creates a new HTTP setting and adds a
new rule, assuming the backend pool and the listener exist already.
## Add the trusted root certificate to the Application Gateway
Add-AzApplicationGatewayTrustedRootCertificate `
-ApplicationGateway $gw `
-Name CustomCARoot `
-CertificateFile "C:\Users\surmb\Downloads\contoso.cer"
$trustedroot = Get-AzApplicationGatewayTrustedRootCertificate `
-Name CustomCARoot `
-ApplicationGateway $gw
$listener = Get-AzApplicationGatewayHttpListener `
-Name basichttps `
-ApplicationGateway $gw
$bepool = Get-AzApplicationGatewayBackendAddressPool `
-Name testbackendpool `
-ApplicationGateway $gw
Add-AzApplicationGatewayProbeConfig `
-ApplicationGateway $gw `
-Name testprobe `
-Protocol Https `
-HostName "www.fabrikam.com" `
-Path "/" `
-Interval 15 `
-Timeout 20 `
-UnhealthyThreshold 3
$probe = Get-AzApplicationGatewayProbeConfig `
-Name testprobe `
-ApplicationGateway $gw
## Add the configuration to the HTTP Setting and don't forget to set the "hostname" field
## to the domain name of the server certificate as this will be set as the SNI header and
## will be used to verify the backend server's certificate. Note that TLS handshake will
## fail otherwise and might lead to backend servers being deemed as Unhealthy by the probes
Add-AzApplicationGatewayBackendHttpSettings `
-ApplicationGateway $gw `
-Name testbackend `
-Port 443 `
-Protocol Https `
-Probe $probe `
-TrustedRootCertificate $trustedroot `
-CookieBasedAffinity Disabled `
-RequestTimeout 20 `
-HostName www.fabrikam.com
$backendhttp = Get-AzApplicationGatewayBackendHttpSettings `
-Name testbackend `
-ApplicationGateway $gw
Add-AzApplicationGatewayRequestRoutingRule `
-ApplicationGateway $gw `
-Name testrule `
-RuleType Basic `
-BackendHttpSettings $backendhttp `
-HttpListener $listener `
-BackendAddressPool $bepool
Next steps
To learn more about SSL\TLS in Application Gateway, see Overview of TLS termination and end to end TLS with
Application Gateway.
Export a trusted client CA certificate chain to use
with client authentication
4/2/2021 • 3 minutes to read • Edit Online
In order to configure mutual authentication with the client, or client authentication, Application Gateway
requires a trusted client CA certificate chain to be uploaded to the gateway. If you have multiple certificate
chains, you'll need to create the chains separately and upload them as different files on the Application Gateway.
In this article, you'll learn how to export a trusted client CA certificate chain that you can use in your client
authentication configuration on your gateway.
Prerequisites
An existing client certificate is required to generate the trusted client CA certificate chain.
4. On the Expor t File Format page, select Base-64 encoded X.509 (.CER)., and then click Next .
5. For File to Expor t , Browse to the location to which you want to export the certificate. For File name ,
name the certificate file. Then, click Next .
For example, you would repeat steps 2-6 from this section on the MSIT CAZ2 intermediate CA to extract it
as its own certificate.
Concatenate all your CA certificates into one file
1. Run the following command with all the CA certificates you extracted earlier.
Windows:
Linux:
Your resulting combined certificate should look something like the following:
Next steps
Now you have the trusted client CA certificate chain. You can add this to your client authentication configuration
on the Application Gateway to allow mutual authentication with your gateway. See configure mutual
authentication using Application Gateway with Portal or configure mutual authentication using Application
Gateway with PowerShell.
Configure TLS policy versions and cipher suites on
Application Gateway
4/2/2021 • 5 minutes to read • Edit Online
Learn how to configure TLS/SSL policy versions and cipher suites on Application Gateway. You can select from a
list of predefined policies that contain different configurations of TLS policy versions and enabled cipher suites.
You also have the ability to define a custom TLS policy based on your requirements.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
NOTE
We recommend using TLS 1.2 as your minimum TLS protocol version for better security on your Application Gateway.
AvailableCipherSuites:
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
TLS_DHE_RSA_WITH_AES_256_CBC_SHA
TLS_DHE_RSA_WITH_AES_128_CBC_SHA
TLS_RSA_WITH_AES_256_GCM_SHA384
TLS_RSA_WITH_AES_128_GCM_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA256
TLS_RSA_WITH_AES_128_CBC_SHA256
TLS_RSA_WITH_AES_256_CBC_SHA
TLS_RSA_WITH_AES_128_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
TLS_DHE_DSS_WITH_AES_256_CBC_SHA
TLS_DHE_DSS_WITH_AES_128_CBC_SHA
TLS_RSA_WITH_3DES_EDE_CBC_SHA
TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
AvailableProtocols:
TLSv1_0
TLSv1_1
TLSv1_2
IMPORTANT
TLS_RSA_WITH_AES_256_CBC_SHA256 must be selected when configuring a custom TLS policy. Application gateway uses
this cipher suite for backend management. You can use this in combination with any other suites, but this one must be
selected as well.
# Create a new listener with the certificate, port, and frontend ip.
$listener = New-AzApplicationGatewayHttpListener -Name listener01 -Protocol Https -FrontendIPConfiguration
$fipconfig -FrontendPort $fp -SslCertificate $cert
# Choose either custom policy or predefined policy and uncomment the one you want to use.
# Update AppGW
# The TLS policy options are not validated or updated on the Application Gateway until this cmdlet is
executed.
$SetGW = Set-AzApplicationGateway -ApplicationGateway $AppGW
Next steps
Visit Application Gateway redirect overview to learn how to redirect HTTP traffic to an HTTPS endpoint.
Check out setting up listener specific SSL policies at setting up SSL listener specific policy through Portal
Configure listener-specific SSL policies on
Application Gateway through portal (Preview)
4/2/2021 • 2 minutes to read • Edit Online
This article describes how to use the Azure portal to configure listener-specific SSL policies on your Application
Gateway. Listener-specific SSL policies allow you to configure specific listeners to use different SSL policies from
each other. You'll still be able to set a default SSL policy that all listeners will use unless overwritten by the
listener-specific SSL policy.
NOTE
Only Standard_v2 and WAF_v2 SKUs support listener specific policies as listener specific policies are part of SSL profiles,
and SSL profiles are only supported on v2 gateways.
If you don't have an Azure subscription, create a free account before you begin.
NOTE
We recommend using TLS 1.2 as TLS 1.2 will be mandated in the future.
1. Search for Application Gateway in portal, select Application gateways , and click on your existing
Application Gateway.
2. Select SSL settings (Preview) from the left-side menu.
3. Click on the plus sign next to SSL Profiles at the top to create a new SSL profile.
4. Enter a name under SSL Profile Name . In this example, we call our SSL profile
applicationGatewaySSLProfile.
5. Go to the SSL Policy tab and check the Enable listener-specific SSL Policy box.
6. Set up your listener-specific SSL policy given your requirements. You can choose between predefined SSL
policies and customizing your own SSL policy. For more information on SSL policies, visit SSL policy
overview. We recommend using TLS 1.2
7. Select Add to save.
NOTE
You don't have to configure client authentication on an SSL profile to associate it to a listener. You can have only
client authentication configure, or only listener specific SSL policy configured, or both configured in your SSL
profile.
The Application Gateway Ingress Controller (AGIC) is a pod within your Kubernetes cluster. AGIC monitors the
Kubernetes Ingress resources, and creates and applies Application Gateway config based on the status of the
Kubernetes cluster.
Outline:
Prerequisites
Azure Resource Manager Authentication (ARM)
Option 1: Set up aad-pod-identity and create Azure Identity on ARMs
Option 2: Using a Service Principal
Install Ingress Controller using Helm
Multi-cluster / Shared Application Gateway: Install AGIC in an environment, where Application Gateway is
shared between one or more AKS clusters and/or other Azure components.
Prerequisites
This document assumes you already have the following tools and infrastructure installed:
AKS with Advanced Networking enabled
Application Gateway v2 in the same virtual network as AKS
AAD Pod Identity installed on your AKS cluster
Cloud Shell is the Azure shell environment, which has az CLI, kubectl , and helm installed. These tools are
required for the commands below.
Please backup your Application Gateway's configuration before installing AGIC:
1. using Azure portal navigate to your Application Gateway instance
2. from Export template click Download
The zip file you downloaded will have JSON templates, bash, and PowerShell scripts you could use to restore
App Gateway should that become necessary
Install Helm
Helm is a package manager for Kubernetes. We will leverage it to install the
application-gateway-kubernetes-ingress package. Use Cloud Shell to install Helm:
1. Install Helm and run the following to add application-gateway-kubernetes-ingress helm package:
Kubernetes RBAC enabled AKS cluster
helm init
2. For the role assignment commands below we need to obtain principalId for the newly created identity:
3. Give the identity Contributor access to your Application Gateway. For this you need the ID of the
Application Gateway, which will look something like this:
/subscriptions/A/resourceGroups/B/providers/Microsoft.Network/applicationGateways/C
4. Give the identity Reader access to the Application Gateway resource group. The resource group ID would
look like: /subscriptions/A/resourceGroups/B . You can get all resource groups with:
az group list --query '[].id'
2. Add the base64 encoded JSON blob to the helm-config.yaml file. More information on helm-config.yaml is
in the next section.
armAuth:
type: servicePrincipal
secretJSON: <Base64-Encoded-Credentials>
wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-
ingress/master/docs/examples/sample-helm-config.yaml -O helm-config.yaml
################################################################################
# Specify which application gateway the ingress controller will manage
#
appgw:
subscriptionId: <subscriptionId>
resourceGroup: <resourceGroupName>
name: <applicationGatewayName>
################################################################################
# Specify which kubernetes namespace the ingress controller will watch
# Default value is "default"
# Leaving this variable out or setting it to blank or empty string would
# result in Ingress Controller observing all acessible namespaces.
#
# kubernetes:
# watchNamespace: <namespace>
################################################################################
# Specify the authentication with Azure Resource Manager
#
# Two authentication methods are available:
# - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
armAuth:
type: aadPodIdentity
identityResourceID: <identityResourceId>
identityClientID: <identityClientId>
################################################################################
# Specify if the cluster is Kubernetes RBAC enabled or not
rbac:
enabled: false # true/false
3. Edit helm-config.yaml and fill in the values for appgw and armAuth .
nano helm-config.yaml
NOTE
The <identity-resource-id> and <identity-client-id> are the properties of the Azure AD Identity you
setup in the previous section. You can retrieve this information by running the following command:
az identity show -g <resourcegroup> -n <identity-name> , where <resourcegroup> is the resource group
in which the top level AKS cluster object, Application Gateway and Managed Identify are deployed.
4. Install Helm chart application-gateway-kubernetes-ingress with the helm-config.yaml configuration from
the previous step
Alternatively you can combine the helm-config.yaml and the Helm command in one step:
5. Check the log of the newly created pod to verify if it started properly
Refer to this how-to guide to understand how you can expose an AKS service over HTTP or HTTPS, to the
internet, using an Azure Application Gateway.
The zip file you downloaded will have JSON templates, bash, and PowerShell scripts you could use to restore
Application Gateway
Example Scenario
Let's look at an imaginary Application Gateway, which manages traffic for two web sites:
dev.contoso.com - hosted on a new AKS, using Application Gateway and AGIC
prod.contoso.com - hosted on an Azure Virtual Machine Scale Set
With default settings, AGIC assumes 100% ownership of the Application Gateway it is pointed to. AGIC
overwrites all of App Gateway's configuration. If we were to manually create a listener for prod.contoso.com (on
Application Gateway), without defining it in the Kubernetes Ingress, AGIC will delete the prod.contoso.com
config within seconds.
To install AGIC and also serve prod.contoso.com from our Virtual Machine Scale Set machines, we must
constrain AGIC to configuring dev.contoso.com only. This is facilitated by instantiating the following CRD:
cat <<EOF | kubectl apply -f -
apiVersion: "appgw.ingress.k8s.io/v1"
kind: AzureIngressProhibitedTarget
metadata:
name: prod-contoso-com
spec:
hostname: prod.contoso.com
EOF
The command above creates an AzureIngressProhibitedTarget object. This makes AGIC (version 0.8.0 and later)
aware of the existence of Application Gateway config for prod.contoso.com and explicitly instructs it to avoid
changing any configuration related to that hostname.
Enable with new AGIC installation
To limit AGIC (version 0.8.0 and later) to a subset of the Application Gateway configuration modify the
helm-config.yaml template. Under the appgw: section, add shared key and set it to to true .
appgw:
subscriptionId: <subscriptionId> # existing field
resourceGroup: <resourceGroupName> # existing field
name: <applicationGatewayName> # existing field
shared: true # <<<<< Add this field to enable shared Application Gateway >>>>>
2. Update Helm:
helm upgrade \
--recreate-pods \
-f helm-config.yaml \
ingress-azure application-gateway-kubernetes-ingress/ingress-azure
As a result your AKS will have a new instance of AzureIngressProhibitedTarget called prohibit-all-targets :
The object prohibit-all-targets , as the name implies, prohibits AGIC from changing config for any host and
path. Helm install with appgw.shared=true will deploy AGIC, but will not make any changes to Application
Gateway.
Broaden permissions
Since Helm with appgw.shared=true and the default prohibit-all-targets blocks AGIC from applying any
config.
Broaden AGIC permissions with:
1. Create a new AzureIngressProhibitedTarget with your specific setup:
cat <<EOF | kubectl apply -f -
apiVersion: "appgw.ingress.k8s.io/v1"
kind: AzureIngressProhibitedTarget
metadata:
name: your-custom-prohibitions
spec:
hostname: your.own-hostname.com
EOF
2. Only after you have created your own custom prohibition, you can delete the default one, which is too
broad:
3. Modify Application Gateway config via portal - add listeners, routing rules, backends etc. The new object
we created ( manually-configured-staging-environment ) will prohibit AGIC from overwriting Application
Gateway configuration related to staging.contoso.com .
How to Install an Application Gateway Ingress
Controller (AGIC) Using a New Application Gateway
3/5/2021 • 6 minutes to read • Edit Online
The instructions below assume Application Gateway Ingress Controller (AGIC) will be installed in an
environment with no pre-existing components.
Alternatively, launch Cloud Shell from Azure portal using the following icon:
Your Azure Cloud Shell already has all necessary tools. Should you choose to use another environment, please
ensure the following command-line tools are installed:
az - Azure CLI: installation instructions
kubectl - Kubernetes command-line tool: installation instructions
helm - Kubernetes package manager: installation instructions
jq - command-line JSON processor: installation instructions
Create an Identity
Follow the steps below to create an Azure Active Directory (AAD) service principal object. Please record the
appId , password , and objectId values - these will be used in the following steps.
The appId and password values from the JSON output will be used in the following steps
2. Use the appId from the previous command's output to get the objectId of the new service principal:
The output of this command is objectId , which will be used in the Azure Resource Manager template
below
3. Create the parameter file that will be used in the Azure Resource Manager template deployment later.
cat <<EOF > parameters.json
{
"aksServicePrincipalAppId": { "value": "$appId" },
"aksServicePrincipalClientSecret": { "value": "$password" },
"aksServicePrincipalObjectId": { "value": "$objectId" },
"aksEnableRBAC": { "value": false }
}
EOF
To deploy an Kubernetes RBAC enabled cluster, set the aksEnableRBAC field to true
Deploy Components
This step will add the following components to your subscription:
Azure Kubernetes Service
Application Gateway v2
Virtual Network with 2 subnets
Public IP Address
Managed Identity, which will be used by AAD Pod Identity
1. Download the Azure Resource Manager template and modify the template as needed.
wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-
ingress/master/deploy/azuredeploy.json -O template.json
2. Deploy the Azure Resource Manager template using az cli . This may take up to 5 minutes.
resourceGroupName="MyResourceGroup"
location="westus2"
deploymentName="ingress-appgw"
3. Once the deployment finished, download the deployment output into a file named
deployment-outputs.json .
# use the deployment-outputs.json created after deployment to get the cluster name and resource group name
aksClusterName=$(jq -r ".aksClusterName.value" deployment-outputs.json)
resourceGroupName=$(jq -r ".resourceGroupName.value" deployment-outputs.json)
Install Helm
Helm is a package manager for Kubernetes. We will leverage it to install the
application-gateway-kubernetes-ingress package:
1. Install Helm and run the following to add application-gateway-kubernetes-ingress helm package:
Kubernetes RBAC enabled AKS cluster
helm init
wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-
ingress/master/docs/examples/sample-helm-config.yaml -O helm-config.yaml
################################################################################
# Specify which application gateway the ingress controller will manage
#
appgw:
subscriptionId: <subscriptionId>
resourceGroup: <resourceGroupName>
name: <applicationGatewayName>
################################################################################
# Specify which kubernetes namespace the ingress controller will watch
# Default value is "default"
# Leaving this variable out or setting it to blank or empty string would
# result in Ingress Controller observing all acessible namespaces.
#
# kubernetes:
# watchNamespace: <namespace>
################################################################################
# Specify the authentication with Azure Resource Manager
#
# Two authentication methods are available:
# - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
armAuth:
type: aadPodIdentity
identityResourceID: <identityResourceId>
identityClientID: <identityClientId>
################################################################################
# Specify if the cluster is Kubernetes RBAC enabled or not
rbac:
enabled: false # true/false
3. Edit the newly downloaded helm-config.yaml and fill out the sections appgw and armAuth .
Values:
verbosityLevel : Sets the verbosity level of the AGIC logging infrastructure. See Logging Levels for
possible values.
appgw.subscriptionId : The Azure Subscription ID in which Application Gateway resides. Example:
a123b234-a3b4-557d-b2df-a0bc12de1234
appgw.resourceGroup : Name of the Azure Resource Group in which Application Gateway was created.
Example: app-gw-resource-group
appgw.name : Name of the Application Gateway. Example: applicationgatewayd0f0
appgw.shared : This boolean flag should be defaulted to false . Set to true should you need a Shared
Application Gateway.
kubernetes.watchNamespace : Specify the name space, which AGIC should watch. This could be a single
string value, or a comma-separated list of namespaces.
armAuth.type : could be aadPodIdentity or servicePrincipal
armAuth.identityResourceID : Resource ID of the Azure Managed Identity
armAuth.identityClientId : The Client ID of the Identity. See below for more information on Identity
armAuth.secretJSON : Only needed when Service Principal Secret type is chosen (when armAuth.type
has been set to servicePrincipal )
NOTE
The identityResourceID and identityClientID are values that were created during the Deploy Components
steps, and could be obtained again using the following command:
<resource-group> in the command above is the resource group of your Application Gateway.
<identity-name> is the name of the created identity. All identities for a given subscription can be listed using:
az identity list
---
apiVersion: v1
kind: Service
metadata:
name: aspnetapp
spec:
selector:
app: aspnetapp
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: aspnetapp
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: aspnetapp
servicePort: 80
EOF
curl https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-
ingress/master/docs/examples/aspnetapp.yaml -o aspnetapp.yaml
Other Examples
This how-to guide contains more examples on how to expose an AKS service via HTTP or HTTPS, to the Internet
with Application Gateway.
Migrate from AGIC Helm to AGIC add-on
3/5/2021 • 2 minutes to read • Edit Online
If you already have AGIC deployed through Helm but want to migrate to AGIC deployed as an AKS add-on, the
following steps will help guide you through the migration process.
Prerequisites
Before you start the migration process, there are a few things to check.
Are you using any features with AGIC Helm that are currently not supported with AGIC add-on?
Are you using more than one AGIC Helm deployment per AKS cluster?
Are you using multiple AGIC Helm deployments to target one Application Gateway?
If you answered yes to any of the questions above, AGIC add-on won't support your use case yet so it will be
best to continue using AGIC Helm in the meantime. Otherwise, continue with the migration process below
during off-business hours.
Next Steps
Application Gateway Ingress Controller Troubleshooting : Troubleshooting guide for AGIC
Application Gateway Ingress Controller Annotations : List of annotations on AGIC
Disable and re-enable AGIC add-on for your AKS
cluster
11/2/2020 • 2 minutes to read • Edit Online
Application Gateway Ingress Controller (AGIC) deployed as an AKS add-on allows you to enable and disable the
add-on with one line in Azure CLI. The life cycle of the Application Gateway will differ when you disable the AGIC
add-on, depending on if the Application Gateway was created by the AGIC add-on, or if it was deployed
separately from the AGIC add-on. You can run the same command to re-enable the AGIC add-on if you ever
disable it, or to enable the AGIC add-on using an existing AKS cluster and Application Gateway.
TIP
If you don't want the Application Gateway to be deleted when disabling the add-on, but it meets both criteria then
remove the "created-by: ingress-appgw" tag to prevent the add-on from deleting your Application Gateway.
Next steps
For more details on how to enable the AGIC add-on using an existing Application Gateway and AKS cluster, see
AGIC add-on brownfield deployment.
Enable Cookie based affinity with an Application
Gateway
3/5/2021 • 2 minutes to read • Edit Online
As outlined in the Azure Application Gateway Documentation, Application Gateway supports cookie based
affinity, which means it can direct subsequent traffic from a user session to the same server for processing.
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/cookie-based-affinity: "true"
spec:
rules:
- http:
paths:
- backend:
serviceName: frontend
servicePort: 80
Enable multiple Namespace support in an AKS
cluster with Application Gateway Ingress Controller
3/5/2021 • 4 minutes to read • Edit Online
Motivation
Kubernetes Namespaces make it possible for a Kubernetes cluster to be partitioned and allocated to subgroups
of a larger team. These subteams can then deploy and manage infrastructure with finer controls of resources,
security, configuration etc. Kubernetes allows for one or more ingress resources to be defined independently
within each namespace.
As of version 0.7 Azure Application Gateway Kubernetes IngressController (AGIC) can ingest events from and
observe multiple namespaces. Should the AKS administrator decide to use App Gateway as an ingress, all
namespaces will use the same instance of Application Gateway. A single installation of Ingress Controller will
monitor accessible namespaces and will configure the Application Gateway it is associated with.
Version 0.7 of AGIC will continue to exclusively observe the default namespace, unless this is explicitly
changed to one or more different namespaces in the Helm configuration (see section below).
Once deployed with the ability to observe multiple namespaces, AGIC will:
list ingress resources from all accessible namespaces
filter to ingress resources annotated with kubernetes.io/ingress.class: azure/application-gateway
compose combined Application Gateway config
apply the config to the associated Application Gateway via ARM
Conflicting Configurations
Multiple namespaced ingress resources could instruct AGIC to create conflicting configurations for a single
Application Gateway. (Two ingresses claiming the same domain for instance.)
At the top of the hierarchy - listeners (IP address, port, and host) and routing rules (binding listener, backend
pool, and HTTP settings) could be created and shared by multiple namespaces/ingresses.
On the other hand - paths, backend pools, HTTP settings, and TLS certificates could be created by one
namespace only and duplicates will be removed.
For example, consider the following duplicate ingress resources defined namespaces staging and production
for www.contoso.com :
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: websocket-ingress
namespace: staging
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- host: www.contoso.com
http:
paths:
- backend:
serviceName: web-service
servicePort: 80
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: websocket-ingress
namespace: production
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- host: www.contoso.com
http:
paths:
- backend:
serviceName: web-service
servicePort: 80
Despite the two ingress resources demanding traffic for www.contoso.com to be routed to the respective
Kubernetes namespaces, only one backend can service the traffic. AGIC would create a configuration on "first
come, first served" basis for one of the resources. If two ingresses resources are created at the same time, the
one earlier in the alphabet will take precedence. From the example above we will only be able to create settings
for the production ingress. Application Gateway will be configured with the following resources:
Listener: fl-www.contoso.com-80
Routing Rule: rr-www.contoso.com-80
Backend Pool: pool-production-contoso-web-service-80-bp-80
HTTP Settings: bp-production-contoso-web-service-80-80-websocket-ingress
Health Probe: pb-production-contoso-web-service-80-websocket-ingress
Note that except for listener and routing rule, the Application Gateway resources created include the name of
the namespace ( production ) for which they were created.
If the two ingress resources are introduced into the AKS cluster at different points in time, it is likely for AGIC to
end up in a scenario where it reconfigures Application Gateway and re-routes traffic from namespace-B to
namespace-A .
For example if you added staging first, AGIC will configure Application Gateway to route traffic to the staging
backend pool. At a later stage, introducing production ingress, will cause AGIC to reprogram Application
Gateway, which will start routing traffic to the production backend pool.
################################################################################
# Specify which application gateway the ingress controller will manage
#
appgw:
subscriptionId: <subscriptionId>
resourceGroup: <resourceGroupName>
name: <applicationGatewayName>
################################################################################
# Specify which kubernetes namespace the ingress controller will watch
# Default value is "default"
# Leaving this variable out or setting it to blank or empty string would
# result in Ingress Controller observing all acessible namespaces.
#
# kubernetes:
# watchNamespace: <namespace>
################################################################################
# Specify the authentication with Azure Resource Manager
#
# Two authentication methods are available:
# - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
armAuth:
type: aadPodIdentity
identityResourceID: <identityResourceId>
identityClientID: <identityClientId>
################################################################################
# Specify if the cluster is Kubernetes RBAC enabled or not
rbac:
enabled: false # true/false
This feature allows to expose the ingress endpoint within the Virtual Network using a private IP.
Pre-requisites
Application Gateway with a Private IP configuration
There are two ways to configure the controller to use Private IP for ingress,
appgw.ingress.kubernetes.io/use-private-ip: "true"
Events:
Type Reason Age From
Message
---- ------ ---- ----
-------
Warning NoPrivateIP 2m (x17 over 2m) azure/application-gateway, prod-ingress-azure-5c9b6fcd4-bctcb
Ingress default/hello-world-ingress requires Application Gateway
applicationgateway3026 has a private IP address
Assign Globally
In case, requirement is to restrict all Ingresses to be exposed over Private IP, use appgw.usePrivateIP: true in
helm config.
Usage
appgw:
subscriptionId: <subscriptionId>
resourceGroup: <resourceGroupName>
name: <applicationGatewayName>
usePrivateIP: true
This will make the ingress controller filter the IP address configurations for a Private IP when configuring the
frontend listeners on the Application Gateway. AGIC will panic and crash if usePrivateIP: true and no Private IP
is assigned.
NOTE
Application Gateway v2 SKU requires a Public IP. Should you require Application Gateway to be private, Attach a
Network Security Group to the Application Gateway's subnet to restrict traffic.
Add Health Probes to your service
11/2/2020 • 2 minutes to read • Edit Online
By default, Ingress controller will provision an HTTP GET probe for the exposed pods. The probe properties can
be customized by adding a Readiness or Liveness Probe to your deployment / pod spec.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetapp
spec:
replicas: 3
template:
metadata:
labels:
service: site
spec:
containers:
- name: aspnetapp
image: mcr.microsoft.com/dotnet/core/samples:aspnetapp
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 3
timeoutSeconds: 1
NOTE
readinessProbe and livenessProbe are supported when configured with httpGet .
Probing on a port other than the one exposed on the pod is currently not supported.
HttpHeaders , InitialDelaySeconds , SuccessThreshold are not supported.
Path /
Host localhost
Protocol HTTP
Timeout 30
Interval 30
UnhealthyThreshold 3
Expose an AKS service over HTTP or HTTPS using
Application Gateway
11/2/2020 • 3 minutes to read • Edit Online
These tutorials help illustrate the usage of Kubernetes Ingress Resources to expose an example Kubernetes
service through the Azure Application Gateway over HTTP or HTTPS.
Prerequisites
Installed ingress-azure helm chart.
Greenfield Deployment : If you are starting from scratch, refer to these installation instructions,
which outlines steps to deploy an AKS cluster with Application Gateway and install application
gateway ingress controller on the AKS cluster.
Brownfield Deployment : If you have an existing AKS cluster and Application Gateway, refer to these
instructions to install application gateway ingress controller on the AKS cluster.
If you want to use HTTPS on this application, you will need a x509 certificate and its private key.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- backend:
serviceName: frontend
servicePort: 80
This ingress will expose the frontend service of the guestbook-all-in-one deployment as a default backend of
the Application Gateway.
Save the above ingress resource as ing-guestbook.yaml .
1. Deploy ing-guestbook.yaml by running:
2. Define the following ingress. In the ingress, specify the name of the secret in the secretName section.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
tls:
- secretName: <guestbook-secret-name>
rules:
- http:
paths:
- backend:
serviceName: frontend
servicePort: 80
NOTE
Replace <guestbook-secret-name> in the above Ingress Resource with the name of your secret. Store the above
Ingress Resource in a file name ing-guestbook-tls.yaml .
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
tls:
- hosts:
- <guestbook.contoso.com>
secretName: <guestbook-secret-name>
rules:
- host: <guestbook.contoso.com>
http:
paths:
- backend:
serviceName: frontend
servicePort: 80
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- path: </other/*>
backend:
serviceName: <other-service>
servicePort: 80
- backend:
serviceName: frontend
servicePort: 80
How to upgrade Application Gateway Ingress
Controller using Helm
11/2/2020 • 2 minutes to read • Edit Online
The Azure Application Gateway Ingress Controller for Kubernetes (AGIC) can be upgraded using a Helm
repository hosted on Azure Storage.
Before we begin the upgrade procedure, ensure that you have added the required repository:
View your currently added Helm repositories with:
Upgrade
1. Refresh the AGIC Helm repository to get the latest release:
Sample response:
helm list
Sample response:
NAME REVISION UPDATED STATUS CHART APP
VERSION NAMESPACE
odd-billygoat 22 Fri Jun 21 15:56:06 2019 FAILED ingress-azure-0.7.0-rc1
0.7.0-rc1 default
The Helm chart installation from the sample response above is named odd-billygoat . We will use this
name for the rest of the commands. Your actual deployment name will most likely differ.
4. Upgrade the Helm deployment to a new version:
helm upgrade \
odd-billygoat \
application-gateway-kubernetes-ingress/ingress-azure \
--version 0.9.0-rc2
Rollback
Should the Helm deployment fail, you can rollback to a previous release.
1. Get the last known healthy release number:
Sample output:
From the sample output of the helm history command it looks like the last successful deployment of our
odd-billygoat was revision 1
This section configures your AKS to leverage LetsEncrypt.org and automatically obtain a TLS/SSL certificate for
your domain. The certificate will be installed on Application Gateway, which will perform SSL/TLS termination
for your AKS cluster. The setup described here uses the cert-manager Kubernetes add-on, which automates the
creation and management of certificates.
Follow the steps below to install cert-manager on your existing AKS cluster.
1. Helm Chart
Run the following script to install the cert-manager helm chart. This will:
create a new cert-manager namespace on your AKS
create the following CRDs: Certificate, Challenge, ClusterIssuer, Issuer, Order
install cert-manager chart (from docs.cert-manager.io)
#!/bin/bash
# Helm v2
helm install \
--name cert-manager \
--namespace cert-manager \
--version v1.0.4 \
jetstack/cert-manager \
# --set installCRDs=true
#To automatically install and manage the CRDs as part of your Helm release,
# you must add the --set installCRDs=true flag to your Helm installation command.
2. ClusterIssuer Resource
Create a ClusterIssuer resource. It is required by cert-manager to represent the Lets Encrypt
certificate authority where the signed certificates will be obtained.
By using the non-namespaced ClusterIssuer resource, cert-manager will issue certificates that can be
consumed from multiple namespaces. Let’s Encrypt uses the ACME protocol to verify that you control a
given domain name and to issue you a certificate. More details on configuring ClusterIssuer properties
here. ClusterIssuer will instruct cert-manager to issue certificates using the Lets Encrypt staging
environment used for testing (the root certificate not present in browser/client trust stores).
The default challenge type in the YAML below is http01 . Other challenges are documented on
letsencrypt.org - Challenge Types
IMPORTANT
Update <YOUR.EMAIL@ADDRESS> in the YAML below
#!/bin/bash
kubectl apply -f - <<EOF
apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
spec:
acme:
# You must replace this email address with your own.
# Let's Encrypt will use this to contact you about expiring
# certificates, and issues related to your account.
email: <YOUR.EMAIL@ADDRESS>
# ACME server URL for Let’s Encrypt’s staging environment.
# The staging environment will not issue trusted certificates but is
# used to ensure that the verification process is working properly
# before moving to production
server: https://acme-staging-v02.api.letsencrypt.org/directory
privateKeySecretRef:
# Secret resource used to store the account's private key.
name: example-issuer-account-key
# Enable the HTTP-01 challenge provider
# you prove ownership of a domain by ensuring that a particular
# file is present at the domain
http01: {}
EOF
3. Deploy App
Create an Ingress resource to Expose the guestbook application using the Application Gateway with the
Lets Encrypt Certificate.
Ensure you Application Gateway has a public Frontend IP configuration with a DNS name (either using
the default azure.com domain, or provision a Azure DNS Zone service, and assign your own custom
domain). Note the annotation certmanager.k8s.io/cluster-issuer: letsencrypt-staging , which tells cert-
manager to process the tagged Ingress resource.
IMPORTANT
Update <PLACEHOLDERS.COM> in the YAML below with your own domain (or the Application Gateway one, for
example 'kh-aks-ingress.westeurope.cloudapp.azure.com')
kubectl apply -f - <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: guestbook-letsencrypt-staging
annotations:
kubernetes.io/ingress.class: azure/application-gateway
certmanager.k8s.io/cluster-issuer: letsencrypt-staging
spec:
tls:
- hosts:
- <PLACEHOLDERS.COM>
secretName: guestbook-secret-name
rules:
- host: <PLACEHOLDERS.COM>
http:
paths:
- backend:
serviceName: frontend
servicePort: 80
EOF
After a few seconds, you can access the guestbook service through the Application Gateway HTTPS url
using the automatically issued staging Lets Encrypt certificate. Your browser may warn you of an
invalid cert authority. The staging certificate is issued by CN=Fake LE Intermediate X1 . This is an indication
that the system worked as expected and you are ready for your production certificate.
4. Production Certificate
Once your staging certificate is setup successfully you can switch to a production ACME server:
a. Replace the staging annotation on your Ingress resource with:
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
b. Delete the existing staging ClusterIssuer you created in the previous step and create a new one by
replacing the ACME server from the ClusterIssuer YAML above with
https://acme-v02.api.letsencrypt.org/directory
5. Certificate Expiration and Renewal
Before the Lets Encrypt certificate expires, cert-manager will automatically update the certificate in the
Kubernetes secret store. At that point, Application Gateway Ingress Controller will apply the updated
secret referenced in the ingress resources it is using to configure the Application Gateway.
Expose a WebSocket server to Application Gateway
11/2/2020 • 2 minutes to read • Edit Online
As outlined in the Application Gateway v2 documentation - it provides native support for the WebSocket and
HTTP/2 protocols. Please note, that for both Application Gateway and the Kubernetes Ingress - there is no user-
configurable setting to selectively enable or disable WebSocket support.
The Kubernetes deployment YAML below shows the minimum configuration used to deploy a WebSocket server,
which is the same as deploying a regular web server:
apiVersion: apps/v1
kind: Deployment
metadata:
name: websocket-server
spec:
selector:
matchLabels:
app: ws-app
replicas: 2
template:
metadata:
labels:
app: ws-app
spec:
containers:
- name: websocket-app
imagePullPolicy: Always
image: your-container-repo.azurecr.io/websockets-app
ports:
- containerPort: 8888
imagePullSecrets:
- name: azure-container-registry-credentials
---
apiVersion: v1
kind: Service
metadata:
name: websocket-app-service
spec:
selector:
app: ws-app
ports:
- protocol: TCP
port: 80
targetPort: 8888
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: websocket-repeater
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- host: ws.contoso.com
http:
paths:
- backend:
serviceName: websocket-app-service
servicePort: 80
Given that all the prerequisites are fulfilled, and you have an Application Gateway controlled by a Kubernetes
Ingress in your AKS, the deployment above would result in a WebSockets server exposed on port 80 of your
Application Gateway's public IP and the ws.contoso.com domain.
The following cURL command would test the WebSocket server deployment:
curl -i -N -H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Origin: http://localhost" \
-H "Host: ws.contoso.com" \
-H "Sec-Websocket-Version: 13" \
-H "Sec-WebSocket-Key: 123" \
http://1.2.3.4:80/ws
As incoming traffic increases, it becomes crucial to scale up your applications based on the demand.
In the following tutorial, we explain how you can use Application Gateway's AvgRequestCountPerHealthyHost
metric to scale up your application. AvgRequestCountPerHealthyHost measures average requests sent to a specific
backend pool and backend HTTP setting combination.
We are going to use following two components:
Azure Kubernetes Metric Adapter - We will use the metric adapter to expose Application Gateway metrics
through the metric server. The Azure Kubernetes Metric Adapter is an open source project under Azure,
similar to the Application Gateway Ingress Controller.
Horizontal Pod Autoscaler - We will use HPA to use Application Gateway metrics and target a deployment
for scaling.
applicationGatewayGroupName="<application-gateway-group-id>"
applicationGatewayGroupId=$(az group show -g $applicationGatewayGroupName -o tsv --query "id")
az ad sp create-for-rbac -n "azure-k8s-metric-adapter-sp" --role "Monitoring Reader" --scopes
applicationGatewayGroupId
2. Now, We will deploy the Azure Kubernetes Metric Adapter using the AAD service principal created above.
3. We will create an ExternalMetric resource with name appgw-request-count-metric . This resource will
instruct the metric adapter to expose AvgRequestCountPerHealthyHost metric for myApplicationGateway
resource in myResourceGroup resource group. You can use the filter field to target a specific backend
pool and backend HTTP setting in the Application Gateway.
apiVersion: azure.com/v1alpha2
kind: ExternalMetric
metadata:
name: appgw-request-count-metric
spec:
type: azuremonitor
azure:
resourceGroup: myResourceGroup # replace with your application gateway's resource group name
resourceName: myApplicationGateway # replace with your application gateway's name
resourceProviderNamespace: Microsoft.Network
resourceType: applicationGateways
metric:
metricName: AvgRequestCountPerHealthyHost
aggregation: Average
filter: BackendSettingsPool eq '<backend-pool-name>~<backend-http-setting-name>' # optional
You can now make a request to the metric server to see if our new metric is getting exposed:
Test your setup by using a load test tool like apache bench:
ab -n10000 http://<applicaiton-gateway-ip-address>/
Next steps
Troubleshoot Ingress Controller issues : Troubleshoot any issues with the Ingress Controller.
Route web traffic based on the URL using Azure
PowerShell
3/10/2021 • 9 minutes to read • Edit Online
You can use Azure PowerShell to configure web traffic routing to specific scalable server pools based on the URL
that is used to access your application. In this article, you create an Azure Application Gateway with three
backend pools using Virtual Machine Scale Sets. Each of the backend pools serves a specific purpose such as,
common data, images, and video. Routing traffic to separate pools ensures that your customers get the
information that they need when they need it.
To enable traffic routing, you create routing rules assigned to listeners that listen on specific ports to ensure web
traffic arrives at the appropriate servers in the pools.
In this article, you learn how to:
Set up the network
Create listeners, URL path map, and rules
Create scalable backend pools
If you prefer, you can complete this procedure using Azure CLI or the Azure portal.
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Static `
-Sku Standard
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$subnet=$vnet.Subnets[0]
$pip = Get-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Name myAGPublicIPAddress
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 80
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSetting `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name myDefaultListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $defaultPool `
-BackendHttpSettings $poolSettings
$appgw = New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $defaultPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku
It may take up to 30 minutes to create the application gateway. Wait until the deployment finishes successfully
before moving on to the next section.
At this point, you have an application gateway that listens for traffic on port 80 and sends that traffic to a default
server pool.
Add image and video backend pools and port
Add backend pools named imagesBackendPool and videoBackendPool to your application gatewayAdd-
AzApplicationGatewayBackendAddressPool. Add the frontend port for the pools using Add-
AzApplicationGatewayFrontendPort. Submit the changes to the application gateway using Set-
AzApplicationGateway.
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
Add-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name imagesBackendPool
Add-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name videoBackendPool
Add-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name bport `
-Port 8080
$backendPort = Get-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name bport
$fipconfig = Get-AzApplicationGatewayFrontendIPConfig `
-ApplicationGateway $appgw
Add-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name backendListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $backendPort
$poolSettings = Get-AzApplicationGatewayBackendHttpSetting `
-ApplicationGateway $appgw `
-Name myPoolSettings
$imagePool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name imagesBackendPool
$videoPool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name videoBackendPool
$defaultPool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name appGatewayBackendPool
$imagePathRule = New-AzApplicationGatewayPathRuleConfig `
-Name imagePathRule `
-Paths "/images/*" `
-BackendAddressPool $imagePool `
-BackendHttpSettings $poolSettings
$videoPathRule = New-AzApplicationGatewayPathRuleConfig `
-Name videoPathRule `
-Paths "/video/*" `
-BackendAddressPool $videoPool `
-BackendHttpSettings $poolSettings
Add-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name urlpathmap `
-PathRules $imagePathRule, $videoPathRule `
-DefaultBackendAddressPool $defaultPool `
-DefaultBackendHttpSettings $poolSettings
$backendlistener = Get-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name backendListener
$urlPathMap = Get-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name urlpathmap
Add-AzApplicationGatewayRequestRoutingRule `
-ApplicationGateway $appgw `
-Name rule2 `
-RuleType PathBasedRouting `
-HttpListener $backendlistener `
-UrlPathMap $urlPathMap
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$backendPool = Get-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool `
-ApplicationGateway $appgw
$imagesPool = Get-AzApplicationGatewayBackendAddressPool `
-Name imagesBackendPool `
-ApplicationGateway $appgw
$videoPool = Get-AzApplicationGatewayBackendAddressPool `
-Name videoBackendPool `
-ApplicationGateway $appgw
$ipConfig = New-AzVmssIpConfig `
-Name myVmssIPConfig$i `
-SubnetId $vnet.Subnets[1].Id `
-SubnetId $vnet.Subnets[1].Id `
-ApplicationGatewayBackendAddressPoolsId $poolId
$vmssConfig = New-AzVmssConfig `
-Location eastus `
-SkuCapacity 2 `
-SkuName Standard_DS2_v2 `
-UpgradePolicyMode Automatic
Set-AzVmssStorageProfile $vmssConfig `
-ImageReferencePublisher MicrosoftWindowsServer `
-ImageReferenceOffer WindowsServer `
-ImageReferenceSku 2016-Datacenter `
-ImageReferenceVersion latest `
-OsDiskCreateOption FromImage
Set-AzVmssOsProfile $vmssConfig `
-AdminUsername azureuser `
-AdminPassword "Azure123456!" `
-ComputerNamePrefix myvmss$i
Add-AzVmssNetworkInterfaceConfiguration `
-VirtualMachineScaleSet $vmssConfig `
-Name myVmssNetConfig$i `
-Primary $true `
-IPConfiguration $ipConfig
New-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmssConfig
}
Install IIS
Each scale set contains two virtual machine instances on which you install IIS. A sample page is created to test if
the application gateway is working.
Update-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmss
}
Change the URL to http://<ip-address>:8080/images/test.htm, replacing your IP address for <ip-address>, and
you should see something like the following example:
Change the URL to http://<ip-address>:8080/video/test.htm, replacing your IP address for <ip-address>, and
you should see something like the following example:
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Next steps
Redirect web traffic based on the URL
Route web traffic based on the URL using the Azure
CLI
3/5/2021 • 5 minutes to read • Edit Online
As an IT administrator managing web traffic, you want to help your customers or users get the information they
need as quickly as possible. One way you can optimize their experience is by routing different kinds of web
traffic to different server resources. This article shows you how to use the Azure CLI to set up and configure
Application Gateway routing for different types of traffic from your application. The routing then directs the
traffic to different server pools based on the URL.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
It may take several minutes to create the application gateway. After the application gateway is created, you can
see these new features:
if [ $i -eq 1 ]
then
poolName="appGatewayBackendPool"
fi
if [ $i -eq 2 ]
then
poolName="imagesBackendPool"
fi
if [ $i -eq 3 ]
then
poolName="videoBackendPool"
fi
az vmss create \
--name myvmss$i \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name $poolName
done
Install NGINX
Change the URL to http://<ip-address>:8080/video/test.html, replacing your IP address for <ip-address>, and
you should see something like the following example.
Clean up resources
When they're no longer needed, remove the resource group, application gateway, and all related resources.
Next steps
Create an application gateway with URL path-based redirection
Create an application gateway that hosts multiple
web sites using Azure PowerShell
3/5/2021 • 7 minutes to read • Edit Online
You can use Azure Powershell to configure the hosting of multiple web sites when you create an application
gateway. In this article, you define backend address pools using virtual machines scale sets. You then configure
listeners and rules based on domains that you own to make sure web traffic arrives at the appropriate servers in
the pools. This article assumes that you own multiple domains and uses examples of www.contoso.com and
www.fabrikam.com.
In this article, you learn how to:
Set up the network
Create an application gateway
Create backend listeners
Create routing rules
Create virtual machine scale sets with the backend pools
Create a CNAME record in your domain
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Dynamic
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$subnet=$vnet.Subnets[0]
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 80
$fabrikamPool = New-AzApplicationGatewayBackendAddressPool `
-Name fabrikamPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
NOTE
With Application Gateway or WAF v2 SKU, you can also configure up to 5 host names per listener and you can use
wildcard characters in the host name. See wildcard host names in listener for more information. To use multiple host
names and wildcard characters in a listener using Azure PowerShell, you must use -HostNames instead of -HostName .
With HostNames, you can mention up to 5 host names as comma-separated values. For example,
-HostNames "*.contoso.com","*.fabrikam.com"
$contosolistener = New-AzApplicationGatewayHttpListener `
-Name contosoListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport `
-HostName "www.contoso.com"
$fabrikamlistener = New-AzApplicationGatewayHttpListener `
-Name fabrikamListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport `
-HostName "www.fabrikam.com"
$contosoRule = New-AzApplicationGatewayRequestRoutingRule `
-Name contosoRule `
-RuleType Basic `
-HttpListener $contosoListener `
-BackendAddressPool $contosoPool `
-BackendHttpSettings $poolSettings
$fabrikamRule = New-AzApplicationGatewayRequestRoutingRule `
-Name fabrikamRule `
-RuleType Basic `
-HttpListener $fabrikamListener `
-BackendAddressPool $fabrikamPool `
-BackendHttpSettings $poolSettings
Create the application gateway
Now that you created the necessary supporting resources, specify parameters for the application gateway using
New-AzApplicationGatewaySku, and then create it using New-AzApplicationGateway.
$sku = New-AzApplicationGatewaySku `
-Name Standard_Medium `
-Tier Standard `
-Capacity 2
$appgw = New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $contosoPool, $fabrikamPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $contosoListener, $fabrikamListener `
-RequestRoutingRules $contosoRule, $fabrikamRule `
-Sku $sku
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$contosoPool = Get-AzApplicationGatewayBackendAddressPool `
-Name contosoPool `
-ApplicationGateway $appgw
$fabrikamPool = Get-AzApplicationGatewayBackendAddressPool `
-Name fabrikamPool `
-ApplicationGateway $appgw
$ipConfig = New-AzVmssIpConfig `
-Name myVmssIPConfig$i `
-SubnetId $vnet.Subnets[1].Id `
-ApplicationGatewayBackendAddressPoolsId $poolId
$vmssConfig = New-AzVmssConfig `
-Location eastus `
-SkuCapacity 2 `
-SkuName Standard_DS2 `
-UpgradePolicyMode Automatic
Set-AzVmssStorageProfile $vmssConfig `
-ImageReferencePublisher MicrosoftWindowsServer `
-ImageReferenceOffer WindowsServer `
-ImageReferenceSku 2016-Datacenter `
-ImageReferenceVersion latest `
-OsDiskCreateOption FromImage
Set-AzVmssOsProfile $vmssConfig `
-AdminUsername azureuser `
-AdminPassword "Azure123456!" `
-ComputerNamePrefix myvmss$i
Add-AzVmssNetworkInterfaceConfiguration `
-VirtualMachineScaleSet $vmssConfig `
-Name myVmssNetConfig$i `
-Primary $true `
-IPConfiguration $ipConfig
New-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmssConfig
}
Install IIS
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/Azure/azure-docs-powershell-
samples/master/application-gateway/iis/appgatewayurl.ps1");
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
Update-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmss
}
Change the address to your other domain and you should see something like the following example:
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Remove-AzResourceGroup -Name myResourceGroupAG
Next steps
Create an application gateway with URL path-based routing rules
Create an application gateway that hosts multiple
web sites using the Azure CLI
3/5/2021 • 6 minutes to read • Edit Online
You can use the Azure CLI to configure the hosting of multiple web sites when you create an application
gateway. In this article, you define backend address pools using virtual machines scale sets. You then configure
listeners and rules based on domains that you own to make sure web traffic arrives at the appropriate servers in
the pools. This article assumes that you own multiple domains and uses examples of www.contoso.com and
www.fabrikam.com.
In this article, you learn how to:
Set up the network
Create an application gateway
Create backend listeners
Create routing rules
Create virtual machine scale sets with the backend pools
Create a CNAME record in your domain
If you prefer, you can complete this procedure using Azure PowerShell.
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features of it:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
Add the backend pools
Add the backend pools that are needed to contain the backend servers using az network application-gateway
address-pool create
Add listeners
Add listeners that are needed to route traffic using az network application-gateway http-listener create.
NOTE
With Application Gateway or WAF v2 SKU, you can also configure up to 5 host names per listener and you can use
wildcard characters in the host name. See wildcard host names in listener for more information. To use multiple host
names and wildcard characters in a listener using Azure CLI, you must use --host-names instead of --host-name . With
host-names, you can mention up to five host names as space-separated values. For example,
--host-names "*.contoso.com *.fabrikam.com"
az network application-gateway http-listener create \
--name contosoListener \
--frontend-ip appGatewayFrontendIP \
--frontend-port appGatewayFrontendPort \
--resource-group myResourceGroupAG \
--gateway-name myAppGateway \
--host-name www.contoso.com
if [ $i -eq 1 ]
then
poolName="contosoPool"
fi
if [ $i -eq 2 ]
then
poolName="fabrikamPool"
fi
az vmss create \
--name myvmss$i \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name $poolName
done
Install NGINX
done
The use of A-records isn't recommended because the VIP may change when the application gateway restarts.
Change the address to your other domain and you should see something like the following example:
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources.
Next steps
Create an application gateway with URL path-based routing rules
Create an application gateway with external
redirection using Azure PowerShell
11/2/2020 • 4 minutes to read • Edit Online
You can use Azure Powershell to configure web traffic redirection when you create an application gateway. In
this tutorial, you configure a listener and rule that redirects web traffic that arrives at the application gateway to
an external site.
In this article, you learn how to:
Set up the network
Create a listener and redirection rule
Create an application gateway
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
O P T IO N EXA M P L E/ L IN K
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.1.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Dynamic
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name defaultPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$defaultListener = New-AzApplicationGatewayHttpListener `
-Name defaultListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$redirectConfig = New-AzApplicationGatewayRedirectConfiguration `
-Name myredirect `
-RedirectType Temporary `
-TargetUrl "https://bing.com"
$redirectRule = New-AzApplicationGatewayRequestRoutingRule `
-Name redirectRule `
-RuleType Basic `
-HttpListener $defaultListener `
-RedirectConfiguration $redirectConfig
Next steps
Create an application gateway with internal redirection using Azure PowerShell
Create an application gateway with external
redirection using the Azure CLI
3/5/2021 • 3 minutes to read • Edit Online
You can use the Azure CLI to configure web traffic redirection when you create an application gateway. In this
tutorial, you configure a listener and rule that redirects web traffic that arrives at the application gateway to an
external site.
In this article, you learn how to:
Set up the network
Create a listener and redirection rule
Create an application gateway
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features of it:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
Add the redirection configuration
Add the redirection configuration that sends traffic from www.consoto.org to the listener for www.contoso.com
to the application gateway using az network application-gateway redirect-config create.
Next steps
Create an application gateway with internal redirection using the Azure CLI
Create an application gateway with HTTP to HTTPS
redirection using the Azure portal
3/5/2021 • 6 minutes to read • Edit Online
You can use the Azure portal to create an application gateway with a certificate for TLS termination. A routing
rule is used to redirect HTTP traffic to the HTTPS port in your application gateway. In this example, you also
create a virtual machine scale set for the backend pool of the application gateway that contains two virtual
machine instances.
In this article, you learn how to:
Create a self-signed certificate
Set up a network
Create an application gateway with the certificate
Add a listener and redirection rule
Create a virtual machine scale set with the default backend pool
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This tutorial requires the Azure PowerShell module version 1.0.0 or later to create a certificate and install IIS.
Run Get-Module -ListAvailable Az to find the version. If you need to upgrade, see Install Azure PowerShell
module. To run the commands in this tutorial, you also need to run Login-AzAccount to create a connection with
Azure.
New-SelfSignedCertificate `
-certstorelocation cert:\localmachine\my `
-dnsname www.contoso.com
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
Thumbprint Subject
---------- -------
E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 CN=www.contoso.com
5. Accept the default values for the other settings and then click OK .
6. Click Choose a vir tual network , click Create new , and then enter these values for the virtual network:
myVNet - for the name of the virtual network.
10.0.0.0/16 - for the virtual network address space.
myAGSubnet - for the subnet name.
10.0.0.0/24 - for the subnet address space.
Next steps
Learn how to Create an application gateway with internal redirection.
Create an application gateway with HTTP to HTTPS
redirection using Azure PowerShell
3/5/2021 • 6 minutes to read • Edit Online
You can use the Azure PowerShell to create an application gateway with a certificate for TLS/SSL termination. A
routing rule is used to redirect HTTP traffic to the HTTPS port in your application gateway. In this example, you
also create a virtual machine scale set for the backend pool of the application gateway that contains two virtual
machine instances.
In this article, you learn how to:
Create a self-signed certificate
Set up a network
Create an application gateway with the certificate
Add a listener and redirection rule
Create a virtual machine scale set with the default backend pool
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
This tutorial requires the Azure PowerShell module version 1.0.0 or later. Run Get-Module -ListAvailable Az to
find the version. If you need to upgrade, see Install Azure PowerShell module. To run the commands in this
tutorial, you also need to run Login-AzAccount to create a connection with Azure.
New-SelfSignedCertificate `
-certstorelocation cert:\localmachine\my `
-dnsname www.contoso.com
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\my
Thumbprint Subject
---------- -------
E1E81C23B3AD33F9B4D1717B20AB65DBB91AC630 CN=www.contoso.com
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.1.0/24
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Dynamic
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$pwd = ConvertTo-SecureString `
-String "Azure123456!" `
-Force `
-AsPlainText
$cert = New-AzApplicationGatewaySslCertificate `
-Name "appgwcert" `
-CertificateFile "c:\appgwcert.pfx" `
-Password $pwd
$defaultListener = New-AzApplicationGatewayHttpListener `
-Name appGatewayHttpListener `
-Protocol Https `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendPort `
-SslCertificate $cert
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultListener `
-BackendAddressPool $defaultPool `
-BackendHttpSettings $poolSettings
Create the application gateway
Now that you created the necessary supporting resources, specify parameters for the application gateway
named myAppGateway using New-AzApplicationGatewaySku, and then create it using New-
AzApplicationGateway with the certificate.
$sku = New-AzApplicationGatewaySku `
-Name Standard_Medium `
-Tier Standard `
-Capacity 2
$appgw = New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $defaultPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendPort `
-HttpListeners $defaultListener `
-RequestRoutingRules $frontendRule `
-Sku $sku `
-SslCertificates $cert
$appgw = Get-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG
Add-AzApplicationGatewayFrontendPort `
-Name httpPort `
-Port 80 `
-ApplicationGateway $appgw
$fipconfig = Get-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-ApplicationGateway $appgw
$fp = Get-AzApplicationGatewayFrontendPort `
-Name httpPort `
-ApplicationGateway $appgw
Add-AzApplicationGatewayHttpListener `
-Name myListener `
-Protocol Http `
-FrontendPort $fp `
-FrontendIPConfiguration $fipconfig `
-ApplicationGateway $appgw
$myListener = Get-AzApplicationGatewayHttpListener `
-Name myListener `
-ApplicationGateway $appgw
$redirectConfig = Get-AzApplicationGatewayRedirectConfiguration `
-Name httpToHttps `
-ApplicationGateway $appgw
Add-AzApplicationGatewayRequestRoutingRule `
-Name rule2 `
-RuleType Basic `
-HttpListener $myListener `
-RedirectConfiguration $redirectConfig `
-ApplicationGateway $appgw
Set-AzApplicationGateway -ApplicationGateway $appgw
Install IIS
Next steps
Rewrite HTTP headers and URL with Application Gateway
Create an application gateway with HTTP to HTTPS
redirection using the Azure CLI
3/5/2021 • 5 minutes to read • Edit Online
You can use the Azure CLI to create an application gateway with a certificate for TLS/SSL termination. A routing
rule is used to redirect HTTP traffic to the HTTPS port in your application gateway. In this example, you also
create a virtual machine scale set for the backend pool of the application gateway that contains two virtual
machine instances.
In this article, you learn how to:
Create a self-signed certificate
Set up a network
Create an application gateway with the certificate
Add a listener and redirection rule
Create a virtual machine scale set with the default backend pool
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out appgwcert.crt
Enter values that make sense for your certificate. You can accept the default values.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features of it:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
az vmss create \
--name myvmss \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name appGatewayBackendPool
Install NGINX
To accept the security warning if you used a self-signed certificate, select Details and then Go on to the
webpage . Your secured NGINX site is then displayed as in the following example:
Next steps
Create an application gateway with internal redirection using the Azure CLI
Create an application gateway with internal
redirection using Azure PowerShell
11/2/2020 • 7 minutes to read • Edit Online
You can use Azure Powershell to configure web traffic redirection when you create an application gateway. In
this article, you define a backend pool using a virtual machines scale set. You then configure listeners and rules
based on domains that you own to make sure web traffic arrives at the appropriate pool. This article assumes
that you own multiple domains and uses examples of www.contoso.com and www.contoso.org.
In this article, you learn how to:
Set up the network
Create an application gateway
Add listeners and redirection rule
Create a virtual machine scale set with the backend pool
Create a CNAME record in your domain
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
O P T IO N EXA M P L E/ L IN K
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.1.0/24
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
$vnet = New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
$pip = New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Dynamic
$contosoPool = New-AzApplicationGatewayBackendAddressPool `
-Name contosoPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$contosoComlistener = New-AzApplicationGatewayHttpListener `
-Name contosoComListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendPort `
-HostName "www.contoso.com"
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name contosoComRule `
-RuleType Basic `
-HttpListener $contosoComListener `
-BackendAddressPool $contosoPool `
-BackendHttpSettings $poolSettings
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$frontendPort = Get-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-ApplicationGateway $appgw
$ipconfig = Get-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-ApplicationGateway $appgw
Add-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name contosoOrgListener `
-Protocol Http `
-FrontendIPConfiguration $ipconfig `
-FrontendPort $frontendPort `
-HostName "www.contoso.org"
Set-AzApplicationGateway -ApplicationGateway $appgw
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$contosoComlistener = Get-AzApplicationGatewayHttpListener `
-Name contosoComListener `
-ApplicationGateway $appgw
$contosoOrglistener = Get-AzApplicationGatewayHttpListener `
-Name contosoOrgListener `
-ApplicationGateway $appgw
Add-AzApplicationGatewayRedirectConfiguration `
-ApplicationGateway $appgw `
-Name redirectOrgtoCom `
-RedirectType Found `
-TargetListener $contosoComListener `
-IncludePath $true `
-IncludeQueryString $true
Set-AzApplicationGateway -ApplicationGateway $appgw
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$contosoOrglistener = Get-AzApplicationGatewayHttpListener `
-Name contosoOrgListener `
-ApplicationGateway $appgw
$redirectConfig = Get-AzApplicationGatewayRedirectConfiguration `
-Name redirectOrgtoCom `
-ApplicationGateway $appgw
Add-AzApplicationGatewayRequestRoutingRule `
-ApplicationGateway $appgw `
-Name contosoOrgRule `
-RuleType Basic `
-HttpListener $contosoOrgListener `
-RedirectConfiguration $redirectConfig
Set-AzApplicationGateway -ApplicationGateway $appgw
Install IIS
Change the address to your other domain, for example https://www.contoso.org and you should see that the
traffic has been redirected back to the listener for www.contoso.com.
Next steps
Application Gateway redirect overview
Create an application gateway with internal
redirection using the Azure CLI
3/5/2021 • 5 minutes to read • Edit Online
You can use the Azure CLI to configure web traffic redirection when you create an application gateway. In this
tutorial, you define a backend pool using a virtual machines scale set. You then configure listeners and rules
based on domains that you own to make sure web traffic arrives at the appropriate pool. This tutorial assumes
that you own multiple domains and uses examples of www.contoso.com and www.contoso.org.
In this article, you learn how to:
Set up the network
Create an application gateway
Add listeners and redirection rule
Create a virtual machine scale set with the backend pool
Create a CNAME record in your domain
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
Use the Bash environment in Azure Cloud Shell.
If you prefer, install the Azure CLI to run CLI reference commands.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish
the authentication process, follow the steps displayed in your terminal. For additional sign-in
options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about
extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the
latest version, run az upgrade.
This tutorial requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is
already installed.
It may take several minutes for the application gateway to be created. After the application gateway is created,
you can see these new features of it:
appGatewayBackendPool - An application gateway must have at least one backend address pool.
appGatewayBackendHttpSettings - Specifies that port 80 and an HTTP protocol is used for communication.
appGatewayHttpListener - The default listener associated with appGatewayBackendPool.
appGatewayFrontendIP - Assigns myAGPublicIPAddress to appGatewayHttpListener.
rule1 - The default routing rule that is associated with appGatewayHttpListener.
az vmss create \
--name myvmss \
--resource-group myResourceGroupAG \
--image UbuntuLTS \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name myVNet \
--subnet myBackendSubnet \
--vm-sku Standard_DS2 \
--upgrade-policy-mode Automatic \
--app-gateway myAppGateway \
--backend-pool-name appGatewayBackendPool
Install NGINX
Run this command in the shell window:
Change the address to your other domain, for example http://www.contoso.org and you should see that the
traffic has been redirected back to the listener for www.contoso.com.
Next steps
In this tutorial, you learned how to:
You can use Azure PowerShell to configure URL-based routing rules when you create an application gateway. In
this article, you create backend pools using virtual machine scale sets. You then create URL routing rules that
make sure web traffic is redirected to the appropriate backend pool.
In this article, you learn how to:
Set up the network
Create an application gateway
Add listeners and routing rules
Create virtual machine scale sets for backend pools
The following example shows site traffic coming from both ports 8080 and 8081 and being directed to the same
backend pools:
If you prefer, you can complete this procedure using Azure CLI.
If you don't have an Azure subscription, create a free account before you begin.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.2.0/24
New-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $backendSubnetConfig, $agSubnetConfig
New-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-Name myAGPublicIPAddress `
-AllocationMethod Dynamic
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$subnet=$vnet.Subnets[0]
$pip = Get-AzPublicIpAddress `
-ResourceGroupName myResourceGroupAG `
-Name myAGPublicIPAddress
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 80
Create the default pool and settings
Create the default backend pool named appGatewayBackendPool for the application gateway using New-
AzApplicationGatewayBackendAddressPool. Configure the settings for the backend pool using New-
AzApplicationGatewayBackendHttpSettings.
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSettings `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 120
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name defaultListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $defaultPool `
-BackendHttpSettings $poolSettings
New-AzApplicationGateway `
-Name myAppGateway `
-ResourceGroupName myResourceGroupAG `
-Location eastus `
-BackendAddressPools $defaultPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
Add-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name imagesBackendPool
Add-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name videoBackendPool
Add-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name bport `
-Port 8080
Add-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name rport `
-Port 8081
$backendPort = Get-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name bport
$redirectPort = Get-AzApplicationGatewayFrontendPort `
-ApplicationGateway $appgw `
-Name rport
$fipconfig = Get-AzApplicationGatewayFrontendIPConfig `
-ApplicationGateway $appgw
Add-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name backendListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $backendPort
Add-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name redirectedListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $redirectPort
$poolSettings = Get-AzApplicationGatewayBackendHttpSettings `
-ApplicationGateway $appgw `
-Name myPoolSettings
$imagePool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name imagesBackendPool
$videoPool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name videoBackendPool
$defaultPool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name appGatewayBackendPool
$imagePathRule = New-AzApplicationGatewayPathRuleConfig `
-Name imagePathRule `
-Paths "/images/*" `
-BackendAddressPool $imagePool `
-BackendHttpSettings $poolSettings
$videoPathRule = New-AzApplicationGatewayPathRuleConfig `
-Name videoPathRule `
-Paths "/video/*" `
-BackendAddressPool $videoPool `
-BackendHttpSettings $poolSettings
Add-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name urlpathmap `
-PathRules $imagePathRule, $videoPathRule `
-DefaultBackendAddressPool $defaultPool `
-DefaultBackendHttpSettings $poolSettings
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$backendListener = Get-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name backendListener
$redirectConfig = Add-AzApplicationGatewayRedirectConfiguration `
-ApplicationGateway $appgw `
-Name redirectConfig `
-RedirectType Found `
-TargetListener $backendListener `
-IncludePath $true `
-IncludeQueryString $true
$poolSettings = Get-AzApplicationGatewayBackendHttpSettings `
-ApplicationGateway $appgw `
-Name myPoolSettings
$defaultPool = Get-AzApplicationGatewayBackendAddressPool `
-ApplicationGateway $appgw `
-Name appGatewayBackendPool
$redirectConfig = Get-AzApplicationGatewayRedirectConfiguration `
-ApplicationGateway $appgw `
-Name redirectConfig
$redirectPathRule = New-AzApplicationGatewayPathRuleConfig `
-Name redirectPathRule `
-Paths "/images/*" `
-RedirectConfiguration $redirectConfig
Add-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name redirectpathmap `
-PathRules $redirectPathRule `
-DefaultBackendAddressPool $defaultPool `
-DefaultBackendHttpSettings $poolSettings
$backendlistener = Get-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name backendListener
$redirectlistener = Get-AzApplicationGatewayHttpListener `
-ApplicationGateway $appgw `
-Name redirectedListener
$urlPathMap = Get-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name urlpathmap
$redirectPathMap = Get-AzApplicationGatewayUrlPathMapConfig `
-ApplicationGateway $appgw `
-Name redirectpathmap
Add-AzApplicationGatewayRequestRoutingRule `
-ApplicationGateway $appgw `
-Name defaultRule `
-RuleType PathBasedRouting `
-HttpListener $backendlistener `
-UrlPathMap $urlPathMap
Add-AzApplicationGatewayRequestRoutingRule `
-ApplicationGateway $appgw `
-Name redirectedRule `
-RuleType PathBasedRouting `
-HttpListener $redirectlistener `
-UrlPathMap $redirectPathMap
$vnet = Get-AzVirtualNetwork `
-ResourceGroupName myResourceGroupAG `
-Name myVNet
$appgw = Get-AzApplicationGateway `
-ResourceGroupName myResourceGroupAG `
-Name myAppGateway
$backendPool = Get-AzApplicationGatewayBackendAddressPool `
-Name appGatewayBackendPool `
-ApplicationGateway $appgw
$imagesPool = Get-AzApplicationGatewayBackendAddressPool `
-Name imagesBackendPool `
-ApplicationGateway $appgw
$videoPool = Get-AzApplicationGatewayBackendAddressPool `
-Name videoBackendPool `
-ApplicationGateway $appgw
for ($i=1; $i -le 3; $i++)
{
if ($i -eq 1)
{
$poolId = $backendPool.Id
}
if ($i -eq 2)
{
$poolId = $imagesPool.Id
}
if ($i -eq 3)
{
$poolId = $videoPool.Id
}
$ipConfig = New-AzVmssIpConfig `
-Name myVmssIPConfig$i `
-SubnetId $vnet.Subnets[1].Id `
-ApplicationGatewayBackendAddressPoolsId $poolId
$vmssConfig = New-AzVmssConfig `
-Location eastus `
-SkuCapacity 2 `
-SkuName Standard_DS2 `
-UpgradePolicyMode Automatic
Set-AzVmssStorageProfile $vmssConfig `
-ImageReferencePublisher MicrosoftWindowsServer `
-ImageReferenceOffer WindowsServer `
-ImageReferenceSku 2016-Datacenter `
-ImageReferenceVersion latest `
-OsDiskCreateOption FromImage
Set-AzVmssOsProfile $vmssConfig `
-AdminUsername <username> `
-AdminPassword "<password>" `
-ComputerNamePrefix myvmss$i
Add-AzVmssNetworkInterfaceConfiguration `
-VirtualMachineScaleSet $vmssConfig `
-Name myVmssNetConfig$i `
-Primary $true `
-IPConfiguration $ipConfig
New-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmssConfig
}
Install IIS
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/Azure/azure-docs-powershell-
samples/master/application-gateway/iis/appgatewayurl.ps1");
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
Update-AzVmss `
-ResourceGroupName myResourceGroupAG `
-Name myvmss$i `
-VirtualMachineScaleSet $vmss
}
Change the URL to http://<ip-address>:8080/video/test.htm, substituting your IP address for <ip-address>, and
you should see something like the following example:
Now, change the URL to http://<ip-address>:8081/images/test.htm, substituting your IP address for <ip-
address>, and you should see traffic redirected back to the images backend pool at http://<ip-
address>:8080/images.
Clean up resources
When no longer needed, remove the resource group, application gateway, and all related resources using
Remove-AzResourceGroup.
Next steps
Learn more about what you can do with application gateway
Rewrite HTTP request and response headers with
Azure Application Gateway - Azure portal
3/5/2021 • 3 minutes to read • Edit Online
This article describes how to use the Azure portal to configure an Application Gateway v2 SKU instance to
rewrite the HTTP headers in requests and responses.
If you don't have an Azure subscription, create a free account before you begin.
Sign in to Azure
Sign in to the Azure portal with your Azure account.
4. Provide a name for the rewrite set and associate it with a routing rule:
Enter the name for the rewrite set in the Name box.
Select one or more of the rules listed in the Associated routing rules list. You can select only
rules that haven't been associated with other rewrite sets. The rules that have already been
associated with other rewrite sets are dimmed.
Select Next .
5. Create a rewrite rule:
Select Add rewrite rule .
Enter a name for the rewrite rule in the Rewrite rule name box. Enter a number in the Rule
sequence box.
6. In this example, we'll rewrite the location header only when it contains a reference to azurewebsites.net.
To do this, add a condition to evaluate whether the location header in the response contains
azurewebsites.net:
Select Add condition and then select the box containing the If instructions to expand it.
Select OK .
7. Add an action to rewrite the location header:
In the Action type list, select Set .
In the Header type list, select Response .
Under Header name , select Common header .
In the Common header list, select Location .
Enter the header value. In this example, we'll use
{http_resp_Location_1}://contoso.com{http_resp_Location_2} as the header value. This value will
replace azurewebsites.net with contoso.com in the location header.
Select OK .
Next steps
To learn more about how to set up some common use cases, see common header rewrite scenarios.
Rewrite HTTP request and response headers with
Azure Application Gateway - Azure PowerShell
3/31/2021 • 3 minutes to read • Edit Online
This article describes how to use Azure PowerShell to configure an Application Gateway v2 SKU instance to
rewrite the HTTP headers in requests and responses.
If you don't have an Azure subscription, create a free account before you begin.
Sign in to Azure
Connect-AzAccount
Select-AzSubscription -Subscription "<sub name>"
Next steps
To learn more about how to set up some common use cases, see common header rewrite scenarios.
Create an application gateway and rewrite HTTP
headers
3/5/2021 • 4 minutes to read • Edit Online
You can use Azure PowerShell to configure rules to rewrite HTTP request and response headers when you create
the new autoscaling and zone-redundant application gateway SKU
In this article, you learn how to:
Create an autoscale virtual network
Create a reserved public IP
Set up your application gateway infrastructure
Specify your http header rewrite rule configuration
Specify autoscale
Create the application gateway
Test the application gateway
If you don't have an Azure subscription, create a free account before you begin.
Prerequisites
This article requires that you run Azure PowerShell locally. You must have Az module version 1.0.0 or later
installed. Run Import-Module Az and then Get-Module Az to find the version. If you need to upgrade, see Install
Azure PowerShell module. After you verify the PowerShell version, run Login-AzAccount to create a connection
with Azure.
Sign in to Azure
Connect-AzAccount
Select-AzSubscription -Subscription "<sub name>"
Retrieve details
Retrieve details of the resource group, subnet, and IP in a local object to create the IP configuration details for
the application gateway.
Specify autoscale
Now you can specify the autoscale configuration for the application gateway. Two autoscaling configuration
types are supported:
Fixed capacity mode . In this mode, the application gateway does not autoscale and operates at a fixed
Scale Unit capacity.
Autoscaling mode . In this mode, the application gateway autoscales based on the application traffic
pattern.
Clean up resources
First explore the resources that were created with the application gateway. Then, when they're no longer needed,
you can use the Remove-AzResourceGroup command to remove the resource group, application gateway, and all
related resources.
Remove-AzResourceGroup -Name $rg
Next steps
Create an application gateway with URL path-based routing rules
Rewrite URL with Azure Application Gateway -
Azure portal (Preview)
11/2/2020 • 3 minutes to read • Edit Online
This article describes how to use the Azure portal to configure an Application Gateway v2 SKU instance to
rewrite URL.
NOTE
URL rewrite feature is in preview and is available only for Standard_v2 and WAF_v2 SKU of Application Gateway. It is not
recommended for use in production environment. To learn more about previews, see terms of use here.
If you don't have an Azure subscription, create a free account before you begin.
Sign in to Azure
Sign in to the Azure portal with your Azure account.
b. Enter a name for the rewrite rule in the Rewrite rule name box. Enter a number in the Rule
sequence box.
6. In this example, we'll rewrite URL path and URL query string only when path contains /article. To do this,
add a condition to evaluate whether the URL path contains /article
a. Select Add condition and then select the box containing the If instructions to expand it.
b. Since in this example we want to check the pattern /article in the URL path, in the Type of variable to
check list, select Ser ver variable .
c. In the Ser ver variable list, select uri_path
d. Under Case-sensitive , select No .
e. In the Operator list, select equal (=) .
f. Enter a regular expression pattern. In this example, we'll use the pattern .*article/(.*)/(.*)
( ) is used to capture the substring for later use in composing the expression for rewriting the URL path.
For more information, see here.
g. Select OK .
Since app service is a multi-tenant service instead of a dedicated deployment, it uses host header in the
incoming request to resolve the request to the correct app service endpoint. Usually, the DNS name of the
application, which in turn is the DNS name associated with the application gateway fronting the app service, is
different from the domain name of the backend app service. Therefore, the host header in the original request
received by the application gateway is not the same as the host name of the backend service. Because of this,
unless the host header in the request from the application gateway to the backend is changed to the host name
of the backend service, the multi-tenant backends are not able to resolve the request to the correct endpoint.
Application Gateway provides a switch called Pick host name from backend target which overrides the host
header in the request with the host name of the back-end when the request is routed from the Application
Gateway to the backend. This capability enables support for multi-tenant back ends such as Azure app service
and API management.
In this article, you learn how to:
Edit a backend pool and add an App Service to it
Edit HTTP Settings with 'Pick Hostname' switch enabled
Prerequisites
Application gateway: Create an application gateway without a backend pool target. For more information,
see Quickstart: Direct web traffic with Azure Application Gateway - Azure portal
App service: If you don't have an existing App service, see App service documentation.
5. Select Save .
Restrict access
The web apps deployed in these examples use public IP addresses that can be accessed directly from the
Internet. This helps with troubleshooting when you are learning about a new feature and trying new things. But
if you intend to deploy a feature into production, you'll want to add more restrictions.
One way you can restrict access to your web apps is to use Azure App Service static IP restrictions. For example,
you can restrict the web app so that it only receives traffic from the application gateway. Use the app service IP
restriction feature to list the application gateway VIP as the only address with access.
Next steps
To learn more about the App service and other multi-tenant support with application gateway, see multi-tenant
service support with application gateway.
Configure App Service with Application Gateway
using PowerShell
11/2/2020 • 5 minutes to read • Edit Online
Application gateway allows you to have an App Service app or other multi-tenant service as a back-end pool
member. In this article, you learn to configure an App Service app with Application Gateway. The first example
shows you how to configure an existing application gateway to use a web app as a back-end pool member. The
second example shows you how to create a new application gateway with a web app as a back-end pool
member.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
# Defines a variable for a dotnet get started web app repository location
$gitrepo="https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"
# Configure GitHub deployment from your GitHub repo and deploy once to web app.
$PropertiesObject = @{
repoUrl = "$gitrepo";
branch = "master";
isManualIntegration = "true";
}
Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName $rg.ResourceGroupName -ResourceType
Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force
Name : publicIP01
ResourceGroupName : ContosoRG
Location : eastus
Id :
/subscriptions/<subscription_id>/resourceGroups/ContosoRG/providers/Microsoft.Network/publicIPAddresses/publ
icIP01
Etag : W/"00000d5b-54ed-4907-bae8-99bd5766d0e5"
ResourceGuid : 00000000-0000-0000-0000-000000000000
ProvisioningState : Succeeded
Tags :
PublicIpAllocationMethod : Dynamic
IpAddress : xx.xx.xxx.xx
PublicIpAddressVersion : IPv4
IdleTimeoutInMinutes : 4
IpConfiguration : {
"Id":
"/subscriptions/<subscription_id>/resourceGroups/ContosoRG/providers/Microsoft.Network/applicationGateways/C
ontosoAppGateway/frontendIP
Configurations/frontend1"
}
DnsSettings : {
"Fqdn": "00000000-0000-xxxx-xxxx-xxxxxxxxxxxx.cloudapp.net"
}
Restrict access
The web apps deployed in these examples use public IP addresses that can be accessed directly from the
Internet. This helps with troubleshooting when you are learning about a new feature and trying new things. But
if you intend to deploy a feature into production, you'll want to add more restrictions.
One way you can restrict access to your web apps is to use Azure App Service static IP restrictions. For example,
you can restrict the web app so that it only receives traffic from the application gateway. Use the app service IP
restriction feature to list the application gateway VIP as the only address with access.
Next steps
Learn how to configure redirection by visiting: Configure redirection on Application Gateway with PowerShell.
Create a custom probe for Application Gateway by
using the portal
3/5/2021 • 8 minutes to read • Edit Online
In this article, you add a custom health probe to an existing application gateway through the Azure portal. Using
the health probes, Azure Application Gateway monitors the health of the resources in the back-end pool.
4. On the Add health probe page, fill out the required information for the probe, and when complete
select OK .
SET T IN G VA L UE DETA IL S
Pick host name from backend Yes or No Sets the host header in the probe to
HTTP settings the host name from the HTTP
settings to which this probe is
associated to. Specially required in
case of multi-tenant backends such
as Azure app service. Learn more
Pick por t from backend HTTP Yes or No Sets the port of the health probe to
settings the port from HTTP settings to
which this probe is associated to. If
you choose no, you can enter a
custom destination port to use
Path / or any valid path The remainder of the full url for the
custom probe. A valid path starts
with '/'. For the default path of
http://contoso.com just use '/'
HTTP Settings selection from dropdown Probe will get associated with the
HTTP setting(s) selected here and
therefore, will monitor the health of
that backend pool which is
associated with the selected HTTP
setting. It will use the same port for
the probe request as the one being
used in the selected HTTP setting.
You can only choose those HTTP
setting(s) which are not associated
with any other custom probe.
Note that only those HTTP setting(s)
are available for association which
have the same protocol as the
protocol chosen in this probe
configuration and have the same
state for the Pick Host Name From
Backend HTTP setting switch.
IMPORTANT
The probe will monitor health of the backend only when it is associated with one or more HTTP Setting(s). It will
monitor back-end resources of those back-end pools which are associated to the HTTP setting(s) to which this
probe is associated with. The probe request will be sent as <protocol>://<hostName>:<port>/<urlPath>.
NOTE
You can choose to save the probe even with unhealthy backend resources, but it is not recommended. This is
because the Application Gateway will not forward requests to the backend servers from the backend pool which
are determined to be unhealthy by the probe. In case there are no healthy resources in a backend pool, you will
not be able to access your application and will get a HTTP 502 error.
4. On the Add health probe blade, fill out the required information for the probe, and when complete
select OK .
SET T IN G VA L UE DETA IL S
Pick host name from backend Yes or No Sets the host header in the probe to
HTTP settings the host name of the back-end
resource in the back-end pool
associated with the HTTP Setting to
which this probe is associated to.
Specially required in case of multi-
tenant backends such as Azure app
service. Learn more
Path / or any valid path The remainder of the full url for the
custom probe. A valid path starts
with '/'. For the default path of
http://contoso.com just use '/'
IMPORTANT
The host name is not the same as server name. This value is the name of the virtual host running on the
application server. The probe is sent to <protocol>://<hostName>:<port from http settings>/<urlPath>
Next steps
View the health of the backend resources as determined by the probe using the backend health view.
Create a custom probe for Azure Application
Gateway (classic) by using PowerShell
3/5/2021 • 4 minutes to read • Edit Online
In this article, you add a custom probe to an existing application gateway with PowerShell. Custom probes are
useful for applications that have a specific health check page or for applications that do not provide a successful
response on the default web application.
IMPORTANT
Azure has two different deployment models for creating and working with resources: Resource Manager and Classic. This
article covers using the Classic deployment model. Microsoft recommends that most new deployments use the Resource
Manager model. Learn how to perform these steps using the Resource Manager model.
NOTE
You need an Azure account to complete these steps. If you don't have an Azure account, you can sign up for a free trial.
To validate that the gateway was created, you can use the Get-AzureApplicationGateway cmdlet.
Get-AzureApplicationGateway AppGwTest
NOTE
The default value for InstanceCount is 2, with a maximum value of 10. The default value for GatewaySize is Medium. You
can choose between Small, Medium, and Large.
VirtualIPs and DnsName are shown as blank because the gateway has not started yet. These values are created
once the gateway is in the running state.
Configure an application gateway by using XML
In the following example, you use an XML file to configure all application gateway settings and commit them to
the application gateway resource.
Copy the following text to Notepad.
<ApplicationGatewayConfiguration xmlns:i="https://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/windowsazure">
<FrontendIPConfigurations>
<FrontendIPConfiguration>
<Name>fip1</Name>
<Type>Private</Type>
</FrontendIPConfiguration>
</FrontendIPConfigurations>
<FrontendPorts>
<FrontendPort>
<Name>port1</Name>
<Port>80</Port>
</FrontendPort>
</FrontendPorts>
<Probes>
<Probe>
<Name>Probe01</Name>
<Protocol>Http</Protocol>
<Host>contoso.com</Host>
<Path>/path/custompath.htm</Path>
<Interval>15</Interval>
<Timeout>15</Timeout>
<UnhealthyThreshold>5</UnhealthyThreshold>
</Probe>
</Probes>
<BackendAddressPools>
<BackendAddressPool>
<Name>pool1</Name>
<IPAddresses>
<IPAddress>1.1.1.1</IPAddress>
<IPAddress>2.2.2.2</IPAddress>
</IPAddresses>
</BackendAddressPool>
</BackendAddressPools>
<BackendHttpSettingsList>
<BackendHttpSettings>
<Name>setting1</Name>
<Port>80</Port>
<Protocol>Http</Protocol>
<CookieBasedAffinity>Enabled</CookieBasedAffinity>
<RequestTimeout>120</RequestTimeout>
<Probe>Probe01</Probe>
</BackendHttpSettings>
</BackendHttpSettingsList>
<HttpListeners>
<HttpListener>
<Name>listener1</Name>
<FrontendIP>fip1</FrontendIP>
<FrontendPort>port1</FrontendPort>
<Protocol>Http</Protocol>
</HttpListener>
</HttpListeners>
<HttpLoadBalancingRules>
<HttpLoadBalancingRule>
<Name>lbrule1</Name>
<Type>basic</Type>
<BackendHttpSettings>setting1</BackendHttpSettings>
<Listener>listener1</Listener>
<BackendAddressPool>pool1</BackendAddressPool>
</HttpLoadBalancingRule>
</HttpLoadBalancingRules>
</ApplicationGatewayConfiguration>
Edit the values between the parentheses for the configuration items. Save the file with extension .xml.
The following example shows how to use a configuration file to set up the application gateway to load balance
HTTP traffic on public port 80 and send network traffic to back-end port 80 between two IP addresses by using a
custom probe.
IMPORTANT
The protocol item Http or Https is case-sensitive.
PA RA M ET ER DESC RIP T IO N
Host and Path Complete URL path that is invoked by the application
gateway to determine the health of the instance. For
example, if you have a website http://contoso.com/, then the
custom probe can be configured for
"http://contoso.com/path/custompath.htm" for probe checks
to have a successful HTTP response.
The probe name is referenced in the <BackendHttpSettings> configuration to assign which back-end pool uses
custom probe settings.
2. Open the XML file in a text editor. Add a <probe> section after <frontendport> .
<Probes>
<Probe>
<Name>Probe01</Name>
<Protocol>Http</Protocol>
<Host>contoso.com</Host>
<Path>/path/custompath.htm</Path>
<Interval>15</Interval>
<Timeout>15</Timeout>
<UnhealthyThreshold>5</UnhealthyThreshold>
</Probe>
</Probes>
In the backendHttpSettings section of the XML, add the probe name as shown in the following example:
<BackendHttpSettings>
<Name>setting1</Name>
<Port>80</Port>
<Protocol>Http</Protocol>
<CookieBasedAffinity>Enabled</CookieBasedAffinity>
<RequestTimeout>120</RequestTimeout>
<Probe>Probe01</Probe>
</BackendHttpSettings>
Next steps
If you want to configure Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL) offload,
see Configure an application gateway for TLS offload.
If you want to configure an application gateway to use with an internal load balancer, see Create an application
gateway with an internal load balancer (ILB).
Create a custom probe for Azure Application
Gateway by using PowerShell for Azure Resource
Manager
3/5/2021 • 6 minutes to read • Edit Online
In this article, you add a custom probe to an existing application gateway with PowerShell. Custom probes are
useful for applications that have a specific health check page or for applications that do not provide a successful
response on the default web application.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
NOTE
You need an Azure account to complete these steps. If you don't have an Azure account, you can sign up for a free trial.
Connect-AzAccount
Get-AzSubscription
4. Create a resource group. You can skip this step if you have an existing resource group.
Azure Resource Manager requires that all resource groups specify a location. This location is used as the default
location for resources in that resource group. Make sure that all commands to create an application gateway use
the same resource group.
In the preceding example, we created a resource group called appgw-RG in location West US .
Create a virtual network and a subnet
The following example creates a virtual network and a subnet for the application gateway. Application gateway
requires its own subnet for use. For this reason, the subnet created for the application gateway should be
smaller than the address space of the VNET to allow for other subnets to be created and used.
# Assign the address range 10.0.0.0/24 to a subnet variable to be used to create a virtual network.
$subnet = New-AzVirtualNetworkSubnetConfig -Name subnet01 -AddressPrefix 10.0.0.0/24
# Create a virtual network named appgwvnet in resource group appgw-rg for the West US region using the
prefix 10.0.0.0/16 with subnet 10.0.0.0/24.
$vnet = New-AzVirtualNetwork -Name appgwvnet -ResourceGroupName appgw-rg -Location 'West US' -AddressPrefix
10.0.0.0/16 -Subnet $subnet
# Assign a subnet variable for the next steps, which create an application gateway.
$subnet = $vnet.Subnets[0]
C O M P O N EN T DESC RIP T IO N
Health probe A custom probe used to monitor the health of the backend
pool members
Frontend por t The port that the application gateway listens for traffic on
#Creates a back-end IP address pool named pool01 with IP addresses 134.170.185.46, 134.170.188.221,
134.170.185.50.
$pool = New-AzApplicationGatewayBackendAddressPool -Name pool01 -BackendIPAddresses 134.170.185.46,
134.170.188.221, 134.170.185.50
# Creates the backend http settings to be used. This component references the $probe created in the previous
command.
$poolSetting = New-AzApplicationGatewayBackendHttpSettings -Name poolsetting01 -Port 80 -Protocol Http -
CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 80
# Creates a frontend port for the application gateway to listen on port 80 that will be used by the
listener.
$fp = New-AzApplicationGatewayFrontendPort -Name frontendport01 -Port 80
# Creates a frontend IP configuration. This associates the $publicip variable defined previously with the
front-end IP that will be used by the listener.
$fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name fipconfig01 -PublicIPAddress $publicip
# Creates the listener. The listener is a combination of protocol and the frontend IP configuration
$fipconfig and frontend port $fp created in previous steps.
$listener = New-AzApplicationGatewayHttpListener -Name listener01 -Protocol Http -FrontendIPConfiguration
$fipconfig -FrontendPort $fp
# Creates the rule that routes traffic to the backend pools. In this example we create a basic rule that
uses the previous defined http settings and backend address pool. It also associates the listener to the
rule
$rule = New-AzApplicationGatewayRequestRoutingRule -Name rule01 -RuleType Basic -BackendHttpSettings
$poolSetting -HttpListener $listener -BackendAddressPool $pool
# Sets the SKU of the application gateway, in this example we create a small standard application gateway
with 2 instances.
$sku = New-AzApplicationGatewaySku -Name Standard_Small -Tier Standard -Capacity 2
# The final step creates the application gateway with all the previously defined components.
$appgw = New-AzApplicationGateway -Name appgwtest -ResourceGroupName appgw-rg -Location 'West US' -
BackendAddressPools $pool -Probes $probe -BackendHttpSettingsCollection $poolSetting -
FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp -HttpListeners
$listener -RequestRoutingRules $rule -Sku $sku
# Load the application gateway resource into a PowerShell variable by using Get-AzApplicationGateway.
$getgw = Get-AzApplicationGateway -Name appgwtest -ResourceGroupName appgw-rg
# Set the backend HTTP settings to remove the reference to the probe. The backend http settings now use the
default probe
$getgw = Set-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $getgw -Name
$getgw.BackendHttpSettingsCollection.name -Port 80 -Protocol http -CookieBasedAffinity Disabled
Next steps
Learn to configure TLS offloading by visiting: Configure TLS Offload
Back-end server certificate is not allow listed for an
application gateway using an Internal Load Balancer
with an App Service Environment
11/2/2020 • 2 minutes to read • Edit Online
This article troubleshoots the following issue: A certificate isn't allow listed when you create an application
gateway by using an Internal Load Balancer (ILB) together with an App Service Environment (ASE) at the back
end when using end-to-end TLS in Azure.
Symptoms
When you create an application gateway by using an ILB with an ASE at the back end, the back-end server may
become unhealthy. This problem occurs if the authentication certificate of the application gateway doesn't match
the configured certificate on the back-end server. See the following scenario as an example:
Application Gateway configuration:
Listener : Multi-site
Por t: 443
Hostname: test.appgwtestase.com
SSL Cer tificate: CN=test.appgwtestase.com
Backend Pool: IP address or FQDN
IP Address:: 10.1.5.11
HTTP Settings: HTTPS
Por t:: 443
Custom Probe: Hostname – test.appgwtestase.com
Authentication Cer tificate: .cer of test.appgwtestase.com
Backend Health: Unhealthy – Backend server certificate is not allow listed with Application Gateway.
ASE configuration:
ILB IP: 10.1.5.11
Domain name: appgwtestase.com
App Ser vice: test.appgwtestase.com
SSL Binding: SNI SSL – CN=test.appgwtestase.com
When you access the application gateway, you receive the following error message because the back-end server
is unhealthy:
502 – Web ser ver received an invalid response while acting as a gateway or proxy ser ver.
Solution
When you don't use a host name to access a HTTPS website, the back-end server will return the configured
certificate on the default website, in case SNI is disabled. For an ILB ASE, the default certificate comes from the
ILB certificate. If there are no configured certificates for the ILB, the certificate comes from the ASE App
certificate.
When you use a fully qualified domain name (FQDN) to access the ILB, the back-end server will return the
correct certificate that's uploaded in the HTTP settings. If that is not the case , consider the following options:
Use FQDN in the back-end pool of the application gateway to point to the IP address of the ILB. This
option only works if you have a private DNS zone or a custom DNS configured. Otherwise, you have to
create an "A" record for a public DNS.
Use the uploaded certificate on the ILB or the default certificate (ILB certificate) in the HTTP settings. The
application gateway gets the certificate when it accesses the ILB's IP for the probe.
Use a wildcard certificate on the ILB and the back-end server, so that for all the websites, the certificate is
common. However, this solution is possible only in case of subdomains and not if each of the websites
require different hostnames.
Clear the Use for App ser vice option for the application gateway in case you are using the IP address
of the ILB.
To reduce overhead, you can upload the ILB certificate in the HTTP settings to make the probe path work. (This
step is just for allow listing. It won't be used for TLS communication.) You can retrieve the ILB certificate by
accessing the ILB with its IP address from your browser on HTTPS then exporting the TLS/SSL certificate in a
Base-64 encoded CER format and uploading the certificate on the respective HTTP settings.
Learn how to diagnose and resolve issues you might encounter when Azure App Service is used as a back-end
target with Azure Application Gateway.
Overview
In this article, you'll learn how to troubleshoot the following issues:
The app service URL is exposed in the browser when there's a redirection.
The app service ARRAffinity cookie domain is set to the app service host name, example.azurewebsites.net,
instead of the original host.
When a back-end application sends a redirection response, you might want to redirect the client to a different
URL than the one specified by the back-end application. You might want to do this when an app service is hosted
behind an application gateway and requires the client to do a redirection to its relative path. An example is a
redirect from contoso.azurewebsites.net/path1 to contoso.azurewebsites.net/path2.
When the app service sends a redirection response, it uses the same host name in the location header of its
response as the one in the request it receives from the application gateway. For example, the client makes the
request directly to contoso.azurewebsites.net/path2 instead of going through the application gateway
contoso.com/path2. You don't want to bypass the application gateway.
This issue might happen for the following main reasons:
You have redirection configured on your app service. Redirection can be as simple as adding a trailing slash
to the request.
You have Azure Active Directory authentication, which causes the redirection.
Also, when you use app services behind an application gateway, the domain name associated with the
application gateway (example.com) is different from the domain name of the app service (say,
example.azurewebsites.net). The domain value for the ARRAffinity cookie set by the app service carries the
example.azurewebsites.net domain name, which isn't desirable. The original host name, example.com, should be
the domain name value in the cookie.
Sample configuration
HTTP listener: Basic or multi-site
Back-end address pool: App Service
HTTP settings: Pick Hostname from Backend Address enabled
Probe: Pick Hostname from HTTP Settings enabled
Cause
App Service is a multitenant service, so it uses the host header in the request to route the request to the correct
endpoint. The default domain name of App Services, *.azurewebsites.net (say, contoso.azurewebsites.net), is
different from the application gateway's domain name (say, contoso.com).
The original request from the client has the application gateway's domain name, contoso.com, as the host name.
You need to configure the application gateway to change the host name in the original request to the app
service's host name when it routes the request to the app service back end. Use the switch Pick Hostname
from Backend Address in the application gateway's HTTP setting configuration. Use the switch Pick
Hostname from Backend HTTP Settings in the health probe configuration.
When the app service does a redirection, it uses the overridden host name contoso.azurewebsites.net in the
location header instead of the original host name contoso.com, unless configured otherwise. Check the
following example request and response headers.
Host: www.contoso.com
## Response headers:
Location: http://contoso.azurewebsites.net/path/
Server: Microsoft-IIS/10.0
Set-Cookie:
ARRAffinity=b5b1b14066f35b3e4533a1974cacfbbd969bf1960b6518aa2c2e2619700e4010;Path=/;HttpOnly;Domain=contoso.
azurewebsites.net
X-Powered-By: ASP.NET
In the previous example, notice that the response header has a status code of 301 for redirection. The location
header has the app service's host name instead of the original host name www.contoso.com .
NOTE
The HTTP header rewrite support is only available for the Standard_v2 and WAF_v2 SKU of Application Gateway. If you
use v1 SKU, we recommend that you migrate from v1 to v2. You want to use rewrite and other advanced capabilities that
are available with v2 SKU.
Your app service is ready to accept the host name www.contoso.com . Change your CNAME entry in DNS to
point it back to the application gateway's FQDN, for example, appgw.eastus.cloudapp.azure.com .
Make sure that your domain www.contoso.com resolves to the application gateway's FQDN when you do a
DNS query.
Set your custom probe to disable Pick Hostname from Backend HTTP Settings . In the Azure portal,
clear the check box in the probe settings. In PowerShell, don't use the -
PickHostNameFromBackendHttpSettings switch in the Set-AzApplicationGatewayProbeConfig
command. In the host name field of the probe, enter your app service's FQDN, example.azurewebsites.net.
The probe requests sent from the application gateway carry this FQDN in the host header.
NOTE
For the next step, make sure that your custom probe isn't associated to your back-end HTTP settings. Your HTTP
settings still have the Pick Hostname from Backend Address switch enabled at this point.
Set your application gateway's HTTP settings to disable Pick Hostname from Backend Address . In the
Azure portal, clear the check box. In PowerShell, don't use the -PickHostNameFromBackendAddress
switch in the Set-AzApplicationGatewayBackendHttpSettings command.
Associate the custom probe back to the back-end HTTP settings, and verify that the back end is healthy.
The application gateway should now forward the same host name, www.contoso.com , to the app service.
The redirection happens on the same host name. Check the following example request and response
headers.
To implement the previous steps using PowerShell for an existing setup, use the sample PowerShell script that
follows. Note how we haven't used the -PickHostname switches in the probe and HTTP settings configuration.
Host: www.contoso.com
## Response headers:
Location: http://www.contoso.com/path/
Server: Microsoft-IIS/10.0
Set-Cookie:
ARRAffinity=b5b1b14066f35b3e4533a1974cacfbbd969bf1960b6518aa2c2e2619700e4010;Path=/;HttpOnly;Domain=www.cont
oso.com
X-Powered-By: ASP.NET
Next steps
If the preceding steps didn't resolve the issue, open a support ticket.
Troubleshoot Azure Application Gateway session
affinity issues
3/5/2021 • 7 minutes to read • Edit Online
Learn how to diagnose and resolve session affinity issues with Azure Application Gateway.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Overview
The cookie-based session affinity feature is useful when you want to keep a user session on the same server. By
using gateway-managed cookies, the Application Gateway can direct subsequent traffic from a user session to
the same server for processing. This is important in cases where session state is saved locally on the server for a
user session.
You can also check the value of the “CookieBasedAffinity ” is set to Enabledunder
"backendHttpSettingsCollection " by using one of the following methods:
Run Get-AzApplicationGatewayBackendHttpSetting in PowerShell
Look through the JSON file by using the Azure Resource Manager template
"cookieBasedAffinity": "Enabled",
The application continues to try to set the cookie on each request until it gets reply.
Cause
This issue occurs because Internet Explorer and other browsers may not store or use the cookie with a short
name URL.
Resolution
To fix this issue, you should access the Application Gateway by using a FQDN. For example, use
http://website.com or http://appgw.website.com .
3. The Diagnostics settings blade provides the settings for the diagnostic logs. In this example, Log
Analytics stores the logs. Click Configure under Log Analytics to set your workspace. You can also use
event hubs and a storage account to save the diagnostic logs.
4. Confirm the settings and then click Save .
View and analyze the Application Gateway access logs
1. In the Azure portal under the Application Gateway resource view, select Diagnostics logs in the
MONITORING section .
2. On the right side, select “ApplicationGatewayAccessLog “ in the drop-down list under Log
categories.
3. In the Application Gateway Access Log list, click the log you want to analyze and export, and then export
the JSON file.
4. Convert the JSON file that you exported in step 3 to CSV file and view them in Excel, Power BI, or any
other data-visualization tool.
5. Check the following data:
ClientIP – This is the client IP address from the connecting client.
ClientPor t - This is the source port from the connecting client for the request.
RequestQuer y – This indicates the destination server that the request is received.
Ser ver-Routed : Back-end pool instance that the request is received.
X-AzureApplicationGateway-LOG-ID : Correlation ID used for the request. It can be used to
troubleshoot traffic issues on the back-end servers. For example: X-AzureApplicationGateway-CACHE-
HIT=0&SERVER-ROUTED=10.0.2.4.
SERVER-STATUS : HTTP response code that Application Gateway received from the back end.
If you see two items are coming from the same ClientIP and Client Port, and they are sent to the same back-end
server, that means the Application Gateway configured correctly.
If you see two items are coming from the same ClientIP and Client Port, and they are sent to the different back-
end servers, that means the request is bouncing between backend servers, select “Application is using
cookie-based affinity but requests still bouncing between back-end ser vers ” at the bottom to
troubleshoot it.
Use web debugger to capture and analyze the HTTP or HTTPS traffics
Web debugging tools like Fiddler, can help you debug web applications by capturing network traffic between the
Internet and test computers. These tools enable you to inspect incoming and outgoing data as the browser
receives/sends them. Fiddler, in this example, has the HTTP replay option that can help you troubleshoot client-
side issues with web applications, especially for authentication kind of issue.
Use the web debugger of your choice. In this sample we will use Fiddler to capture and analyze http or https
traffics, follow the instructions:
1. Download the Fiddler tool at https://www.telerik.com/download/fiddler.
NOTE
Choose Fiddler4 if the capturing computer has .NET 4 installed. Otherwise, choose Fiddler2.
3. When you open Fiddler, it should automatically start capturing traffic (notice the Capturing at lower-left-
hand corner). Press F12 to start or stop traffic capture.
4. Most likely, you will be interested in decrypted HTTPS traffic, and you can enable HTTPS decryption by
selecting Tools > Fiddler Options , and check the box " Decr ypt HTTPS traffic ".
5. You can remove previous unrelated sessions before reproducing the issue by clicking X (icon) > Remove
All as follow screenshot:
6. Once you have reproduced the issue, save the file for review by selecting File > Save > All Sessions...
7. Check and analyze the session logs to determine what the issue is.
For examples:
Example A: You find a session log that the request is sent from the client, and it goes to the public IP
address of the Application Gateway, click this log to view the details. On the right side, data in the bottom
box is what the Application Gateway is returning to the client. Select the “RAW” tab and determine
whether the client is receiving a "Set-Cookie: ARRAffinity= ARRAffinityValue." If there's no cookie,
session affinity isn't set, or the Application Gateway isn't applying cookie back to the client.
NOTE
This ARRAffinity value is the cookie-id, that the Application Gateway sets for the client to be sent to a particular
back-end server.
Example B: The next session log followed by the previous one is the client responding back to the
Application Gateway, which has set the ARRAAFFINITY. If the ARRAffinity cookie-id matches, the packet
should be sent to the same back-end server that was used previously. Check the next several lines of http
communication to see whether the client's ARRAffinity cookie is changing.
NOTE
For the same communication session, the cookie should not to change. Check the top box on the right side, select
"Cookies" tab to see whether the client is using the cookie and sending it back to the Application Gateway. If not, the
client browser isn't keeping and using the cookie for conversations. Sometimes, the client might lie.
Next steps
If the preceding steps do not resolve the issue, open a support ticket.
Troubleshooting bad gateway errors in Application
Gateway
3/5/2021 • 6 minutes to read • Edit Online
Learn how to troubleshoot bad gateway (502) errors received when using Azure Application Gateway.
NOTE
This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended
PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Overview
After configuring an application gateway, one of the errors that you may see is "Server Error: 502 - Web server
received an invalid response while acting as a gateway or proxy server". This error may happen for the following
main reasons:
NSG, UDR, or Custom DNS is blocking access to backend pool members.
Back-end VMs or instances of virtual machine scale set aren't responding to the default health probe.
Invalid or improper configuration of custom health probes.
Azure Application Gateway's back-end pool isn't configured or empty.
None of the VMs or instances in virtual machine scale set are healthy.
Request time-out or connectivity issues with user requests.
Check presence of custom DNS in the VNet. DNS can be checked by looking at details of the VNet properties
in the output.
If present, ensure that the DNS server can resolve the backend pool member's FQDN correctly.
Solution
Ensure that a default site is configured and is listening at 127.0.0.1.
If BackendHttpSetting specifies a port other than 80, the default site should be configured to listen at that
port.
The call to http://127.0.0.1:port should return an HTTP result code of 200. This should be returned within
the 30-second timeout period.
Ensure that the port configured is open and that there are no firewall rules or Azure Network Security
Groups, which block incoming or outgoing traffic on the port configured.
If Azure classic VMs or Cloud Service is used with a FQDN or a public IP, ensure that the corresponding
endpoint is opened.
If the VM is configured via Azure Resource Manager and is outside the VNet where the application gateway is
deployed, a Network Security Group must be configured to allow access on the desired port.
Name Name of the probe. This name is used to refer to the probe
in back-end HTTP settings.
Protocol Protocol used to send the probe. The probe uses the
protocol defined in the back-end HTTP settings
Host Host name to send the probe. Applicable only when multi-
site is configured on the application gateway. This is different
from VM host name.
Path Relative path of the probe. The valid path starts from '/'. The
probe is sent to <protocol>://<host>:<port><path>
Unhealthy threshold Probe retry count. The back-end server is marked down
after the consecutive probe failure count reaches the
unhealthy threshold.
Solution
Validate that the Custom Health Probe is configured correctly as the preceding table. In addition to the
preceding troubleshooting steps, also ensure the following:
Ensure that the probe is correctly specified as per the guide.
If the application gateway is configured for a single site, by default the Host name should be specified as
127.0.0.1 , unless otherwise configured in custom probe.
Ensure that a call to http://<host>:<port><path> returns an HTTP result code of 200.
Ensure that Interval, Timeout, and UnhealtyThreshold are within the acceptable ranges.
If using an HTTPS probe, make sure that the backend server doesn't require SNI by configuring a fallback
certificate on the backend server itself.
Request time-out
Cause
When a user request is received, the application gateway applies the configured rules to the request and routes
it to a back-end pool instance. It waits for a configurable interval of time for a response from the back-end
instance. By default, this interval is 20 seconds. If the application gateway does not receive a response from
back-end application in this interval, the user request gets a 502 error.
Solution
Application Gateway allows you to configure this setting via the BackendHttpSetting, which can be then applied
to different pools. Different back-end pools can have different BackendHttpSetting, and a different request time-
out configured.
Empty BackendAddressPool
Cause
If the application gateway has no VMs or virtual machine scale set configured in the back-end address pool, it
can't route any customer request and sends a bad gateway error.
Solution
Ensure that the back-end address pool isn't empty. This can be done either via PowerShell, CLI, or portal.
The output from the preceding cmdlet should contain non-empty back-end address pool. The following example
shows two pools returned which are configured with a FQDN or an IP addresses for the backend VMs. The
provisioning state of the BackendAddressPool must be 'Succeeded'.
BackendAddressPoolsText:
[{
"BackendAddresses": [{
"ipAddress": "10.0.0.10",
"ipAddress": "10.0.0.11"
}],
"BackendIpConfigurations": [],
"ProvisioningState": "Succeeded",
"Name": "Pool01",
"Etag": "W/\"00000000-0000-0000-0000-000000000000\"",
"Id": "/subscriptions/<subscription id>/resourceGroups/<resource group
name>/providers/Microsoft.Network/applicationGateways/<application gateway name>/backendAddressPools/pool01"
}, {
"BackendAddresses": [{
"Fqdn": "xyx.cloudapp.net",
"Fqdn": "abc.cloudapp.net"
}],
"BackendIpConfigurations": [],
"ProvisioningState": "Succeeded",
"Name": "Pool02",
"Etag": "W/\"00000000-0000-0000-0000-000000000000\"",
"Id": "/subscriptions/<subscription id>/resourceGroups/<resource group
name>/providers/Microsoft.Network/applicationGateways/<application gateway name>/backendAddressPools/pool02"
}]
Next steps
If the preceding steps don't resolve the issue, open a support ticket.
Troubleshooting mutual authentication errors in
Application Gateway (Preview)
4/2/2021 • 5 minutes to read • Edit Online
Learn how to troubleshoot problems with mutual authentication when using Application Gateway.
Overview
After configuring mutual authentication on an Application Gateway, there can be a number of errors that appear
when trying to use mutual authentication. Some common causes for errors include:
Uploaded a certificate or certificate chain without a root CA certificate
Uploaded a certificate chain with multiple root CA certificates
Uploaded a certificate chain that only contained a leaf certificate without a CA certificate
Validation errors due to issuer DN mismatch
We'll go through different scenarios that you might run into and how to troubleshoot those scenarios. We'll then
address error codes and explain likely causes for certain error codes you might be seeing with mutual
authentication.
The -cert flag is the leaf certificate, the -key flag is the client private key file.
For more information on how to use the OpenSSL s_client command, check out their manual page.
SslClientVerify is FAILED
Problem
The property sslClientVerify is appearing as "FAILED" in your access logs.
Solution
There are a number of potential causes for failures in the access logs. Below is a list of common causes for
failure:
Unable to get issuer cer tificate: The issuer certificate of the client certificate couldn't be found. This
normally means the trusted client CA certificate chain is not complete on the Application Gateway. Validate
that the trusted client CA certificate chain uploaded on the Application Gateway is complete.
Unable to get local issuer cer tificate: Similar to unable to get issuer certificate, the issuer certificate of
the client certificate couldn't be found. This normally means the trusted client CA certificate chain is not
complete on the Application Gateway. Validate that the trusted client CA certificate chain uploaded on the
Application Gateway is complete.
Unable to verify the first cer tificate: Unable to verify the client certificate. This error occurs specifically
when the client presents only the leaf certificate, whose issuer is not trusted. Validate that the trusted client
CA certificate chain uploaded on the Application Gateway is complete.
Unable to verify the client cer tificate issuer : This error occurs when the configuration
VerifyClientCertIssuerDN is set to true. This typically happens when the Issuer DN of the client certificate
doesn't match the ClientCertificateIssuerDN extracted from the trusted client CA certificate chain uploaded
by the customer. For more information about how Application Gateway extracts the
ClientCertificateIssuerDN, check out Application Gateway extracting issuer DN. As best practice, make sure
you're uploading one certificate chain per file to Application Gateway.
For more information on how to extract the entire trusted client CA certificate chain to upload to Application
Gateway, see how to extract trusted client CA certificate chains.
Azure Cloud Shell is the most convenient way to troubleshoot any problems with your AKS and AGIC
installation. Launch your shell from shell.azure.com or by clicking the link:
Copy and paste all lines at once from the script above into a Azure Cloud Shell. Please ensure the entire
command is copied - starting with cat and including the last EOF .
After a successful deployment of the app above your AKS cluster will have a new Pod, Service and an Ingress.
Get the list of pods with Cloud Shell: kubectl get pods -o wide . We expect for a pod named 'test-agic-app-pod'
to have been created. It will have an IP address. This address must be within the VNET of the Application
Gateway, which is used with AKS.
Get the list of services: kubectl get services -o wide . We expect to see a service named 'test-agic-app-service'.
Get the list of the ingresses: kubectl get ingress . We expect an Ingress resource named 'test-agic-app-ingress'
to have been created. The resource will have a host name 'test.agic.contoso.com'.
One of the pods will be AGIC. kubectl get pods will show a list of pods, one of which will begin with 'ingress-
azure'. Get all logs of that pod with kubectl logs <name-of-ingress-controller-pod> to verify that we have had a
successful deployment. A successful deployment would have added the following lines to the log:
Alternatively, from Cloud Shell we can retrieve only the lines indicating successful Application Gateway
configuration with kubectl logs <ingress-azure-....> | grep 'Applied App Gateway config in' , where
<ingress-azure....> should be the exact name of the AGIC pod.
Routing Rule:
Backend Pool:
There will be one IP address in the backend address pool and it will match the IP address of the Pod
we observed earlier with kubectl get pods -o wide
Finally we can use the cURL command from within Cloud Shell to establish an HTTP connection to the newly
deployed app:
1. Use kubectl get ingress to get the Public IP address of Application Gateway
2. Use curl -I -H 'test.agic.contoso.com' <publitc-ip-address-from-previous-command>
A result of HTTP/1.1 200 OK indicates that the Application Gateway + AKS + AGIC system is working as
expected.
2. One or more ser vices , referencing the pods above via matching selector labels. Verify this from Cloud
Shell with kubectl get services -o wide
4. View annotations of the ingress above: kubectl get ingress aspnetapp -o yaml (substitute aspnetapp
with the name of your ingress)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: azure/application-gateway
name: aspnetapp
spec:
backend:
serviceName: aspnetapp
servicePort: 80
The AGIC pod should be in the default namespace (see column NAMESPACE ). A healthy pod would have
Running in the STATUS column. There should be at least one AGIC pod.
If the AGIC pod is not healthy ( STATUS column from the command above is not Running ):
get logs to understand why: kubectl logs <pod-name>
for the previous instance of the pod: kubectl logs <pod-name> --previous
describe the pod to get more context: kubectl describe pod <pod-name>
Do you have a Kubernetes Service and Ingress resources?
AGIC emits Kubernetes events for certain critical errors. You can view these:
in your terminal via kubectl get events --sort-by=.metadata.creationTimestamp
in your browser using the Kubernetes Web UI (Dashboard)
Logging Levels
AGIC has 3 logging levels. Level 1 is the default one and it shows minimal number of log lines. Level 5, on the
other hand, would display all logs, including sanitized contents of config applied to ARM.
The Kubernetes community has established 9 levels of logging for the kubectl tool. In this repository we are
utilizing 3 of these, with similar semantics:
The verbosity levels are adjustable via the verbosityLevel variable in the helm-config.yaml file. Increase
verbosity level to 5 to get the JSON config dispatched to ARM:
add verbosityLevel: 5 on a line by itself in helm-config.yaml and re-install
get logs with kubectl logs <pod-name>
Sample Helm config file
# This file contains the essential configs for the ingress controller helm chart
################################################################################
# Specify which application gateway the ingress controller will manage
#
appgw:
subscriptionId: <subscriptionId>
resourceGroup: <resourceGroupName>
name: <applicationGatewayName>
################################################################################
# Specify which kubernetes namespace the ingress controller will watch
# Default value is "default"
# Leaving this variable out or setting it to blank or empty string would
# result in Ingress Controller observing all acessible namespaces.
#
# kubernetes:
# watchNamespace: <namespace>
################################################################################
# Specify the authentication with Azure Resource Manager
#
# Two authentication methods are available:
# - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
armAuth:
type: aadPodIdentity
identityResourceID: <identityResourceId>
identityClientID: <identityClientId>
################################################################################
# Specify if the cluster is Kubernetes RBAC enabled or not
rbac:
enabled: false # true/false
Azure Resource Health helps you diagnose and get support when an Azure service problem affects your
resources. It informs you about the current and past health of your resources. And it provides technical support
to help you mitigate problems.
For Application Gateway, Resource Health relies on signals emitted by the gateway to assess whether it's healthy
or not. If the gateway is unhealthy, Resource Health analyzes additional information to determine the source of
the problem. It also identifies actions that Microsoft is taking or what you can do to fix the problem.
For additional details on how health is assessed, review the full list of resource types and health checks in Azure
Resource Health.
The health status for Application Gateway is displayed as one of the following statuses:
Available
An Available status means the service hasn't detected any events that affect the health of the resource. You'll
see the Recently resolved notification in cases where the gateway has recovered from unplanned downtime
during the last 24 hours.
Unavailable
An Unavailable status means the service has detected an ongoing platform or non-platform event that affects
the health of the gateway.
Platform events
Platform events are triggered by multiple components of the Azure infrastructure. They include both scheduled
actions (for example, planned maintenance) and unexpected incidents (for example, an unplanned host reboot).
Resource Health provides additional details on the event and the recovery process. It also enables you to contact
support even if you don't have an active Microsoft support agreement.
Unknown
The Unknown health status indicates Resource Health hasn't received information about the gateway for more
than 10 minutes. This status isn't a definitive indication of the state of the gateway. But it's an important data
point in the troubleshooting process.
If the gateway is running as expected, the status changes to Available after a few minutes.
If you're experiencing problems, the Unknown health status might suggest that an event in the platform is
affecting the gateway.
Degraded
The Degraded health status indicates your gateway has detected a loss in performance, although it's still
available for usage.
Next steps
To learn about troubleshooting Application Gateway Web Application Firewall (WAF), see Troubleshoot Web
Application Firewall (WAF) for Azure Application Gateway.
Use Log Analytics to examine Application Gateway
Web Application Firewall (WAF) Logs
3/5/2021 • 2 minutes to read • Edit Online
Once your Application Gateway WAF is operational, you can enable logs to inspect what is happening with each
request. Firewall logs give insight to what the WAF is evaluating, matching, and blocking. With Log Analytics,
you can examine the data inside the firewall logs to give even more insights. For more information about
creating a Log Analytics workspace, see Create a Log Analytics workspace in the Azure portal. For more
information about log queries, see Overview of log queries in Azure Monitor.
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.NETWORK" and Category == "ApplicationGatewayFirewallLog"
You can drill down into the data, and plot graphs or create visualizations from here. See the following queries as
a starting point:
Matched/Blocked requests by IP
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.NETWORK" and Category == "ApplicationGatewayFirewallLog"
| summarize count() by clientIp_s, bin(TimeGenerated, 1m)
| render timechart
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.NETWORK" and Category == "ApplicationGatewayFirewallLog"
| summarize count() by ruleId_s, bin(TimeGenerated, 1m)
| where count_ > 10
| render timechart
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.NETWORK" and Category == "ApplicationGatewayFirewallLog"
| summarize Count=count() by details_file_s, action_s
| top 5 by Count desc
| render piechart
Next steps
Back-end health, diagnostic logs, and metrics for Application Gateway
Troubleshoot backend health issues in Application
Gateway
3/31/2021 • 19 minutes to read • Edit Online
Overview
By default, Azure Application Gateway probes backend servers to check their health status and to check whether
they're ready to serve requests. Users can also create custom probes to mention the host name, the path to be
probed, and the status codes to be accepted as Healthy. In each case, if the backend server doesn't respond
successfully, Application Gateway marks the server as Unhealthy and stops forwarding requests to the server.
After the server starts responding successfully, Application Gateway resumes forwarding the requests.
How to check backend health
To check the health of your backend pool, you can use the Backend Health page on the Azure portal. Or, you
can use Azure PowerShell, CLI, or REST API.
The status retrieved by any of these methods can be any one of the following:
Healthy
Unhealthy
Unknown
If the backend health status for a server is Healthy, it means that Application Gateway will forward the requests
to that server. But if the backend health for all the servers in a backend pool is Unhealthy or unknown, you
might encounter problems when you try to access applications. This article describes the symptoms, cause, and
resolution for each of the errors shown.
Or if you're using an Azure PowerShell, CLI, or Azure REST API query, you'll get a response that resembles the
following:
PS C:\Users\testuser\> Get-AzApplicationGatewayBackendHealth -Name "appgw1" -ResourceGroupName "rgOne"
BackendAddressPools :
{Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayBackendHealthPool}
BackendAddressPoolsText : [
{
"BackendAddressPool": {
"Id": "/subscriptions/536d30b8-665b-40fc-bd7e-
68c65f816365/resourceGroups/rgOne/providers/Microsoft.Network/applicationGateways/appgw1/b
ackendAddressPools/appGatewayBackendPool"
},
"BackendHttpSettingsCollection": [
{
"BackendHttpSettings": {
"TrustedRootCertificates": [],
"Id": "/subscriptions/536d30b8-665b-40fc-bd7e-
68c65f816365/resourceGroups/rgOne/providers/Microsoft.Network/applicationGateways/appg
w1/backendHttpSettingsCollection/appGatewayBackendHttpSettings"
},
"Servers": [
{
"Address": "10.0.0.5",
"Health": "Healthy"
},
{
"Address": "10.0.0.6",
"Health": "Unhealthy"
}
]
}
]
}
]
After you receive an Unhealthy backend server status for all the servers in a backend pool, requests aren't
forwarded to the servers, and Application Gateway returns a "502 Bad Gateway" error to the requesting client.
To troubleshoot this issue, check the Details column on the Backend Health tab.
The message displayed in the Details column provides more detailed insights about the issue, and based on
those, you can start troubleshooting the issue.
NOTE
The default probe request is sent in the format of <protocol>://127.0.0.1:<port>/. For example, http://127.0.0.1:80 for an
http probe on port 80. Only HTTP status codes of 200 through 399 are considered healthy. The protocol and destination
port are inherited from the HTTP settings. If you want Application Gateway to probe on a different protocol, host name,
or path and to recognize a different status code as Healthy, configure a custom probe and associate it with the HTTP
settings.
Error messages
Backend server timeout
Message: Time taken by the backend to respond to application gateway's health probe is more than the
timeout threshold in the probe setting.
Cause: After Application Gateway sends an HTTP(S) probe request to the backend server, it waits for a response
from the backend server for a configured period. If the backend server doesn't respond within the configured
period (the timeout value), it's marked as Unhealthy until it starts responding within the configured timeout
period again.
Resolution: Check why the backend server or application isn't responding within the configured timeout
period, and also check the application dependencies. For example, check whether the database has any issues
that might trigger a delay in response. If you're aware of the application's behavior and it should respond only
after the timeout value, increase the timeout value from the custom probe settings. You must have a custom
probe to change the timeout value. For information about how to configure a custom probe, see the
documentation page.
To increase the timeout value, follow these steps:
1. Access the backend server directly and check the time taken for the server to respond on that page. You
can use any tool to access the backend server, including a browser using developer tools.
2. After you've figured out the time taken for the application to respond, select the Health Probes tab and
then select the probe that's associated with your HTTP settings.
3. Enter any timeout value that's greater than the application response time, in seconds.
4. Save the custom probe settings and check whether the backend health shows as Healthy now.
DNS resolution error
Message: Application Gateway could not create a probe for this backend. This usually happens when the FQDN
of the backend has not been entered correctly.
Cause: If the backend pool is of type IP Address/FQDN or App Service, Application Gateway resolves to the IP
address of the FQDN entered through Domain Name System (DNS) (custom or Azure default) and tries to
connect to the server on the TCP port mentioned in the HTTP Settings. But if this message is displayed, it
suggests that Application Gateway couldn't successfully resolve the IP address of the FQDN entered.
Resolution:
1. Verify that the FQDN entered in the backend pool is correct and that it's a public domain, and then try to
resolve it from your local machine.
2. If you can resolve the IP address, there might be something wrong with the DNS configuration in the
virtual network.
3. Check whether the virtual network is configured with a custom DNS server. If it is, check the DNS server
about why it can't resolve to the IP address of the specified FQDN.
4. If you're using Azure default DNS, check with your domain name registrar about whether proper A record
or CNAME record mapping has been completed.
5. If the domain is private or internal, try to resolve it from a VM in the same virtual network. If you can
resolve it, restart Application Gateway and check again. To restart Application Gateway, you need to stop
and start by using the PowerShell commands described in these linked resources.
TCP connect error
Message: Application Gateway could not connect to the backend. Please check that the backend responds on
the port used for the probe. Also check whether any NSG/UDR/Firewall is blocking access to the Ip and port of
this backend
Cause: After the DNS resolution phase, Application Gateway tries to connect to the backend server on the TCP
port that's configured in the HTTP settings. If Application Gateway can't establish a TCP session on the port
specified, the probe is marked as Unhealthy with this message.
Solution: If you receive this error, follow these steps:
1. Check whether you can connect to the backend server on the port mentioned in the HTTP settings by
using a browser or PowerShell. For example, run the following command:
Test-NetConnection -ComputerName www.bing.com -Port 443
2. If the port mentioned is not the desired port, enter the correct port number for Application Gateway to
connect to the backend server
3. If you can't connect on the port from your local machine as well, then:
a. Check the network security group (NSG) settings of the backend server's network adapter and subnet
and whether inbound connections to the configured port are allowed. If they aren't, create a new rule to
allow the connections. To learn how to create NSG rules, see the documentation page.
b. Check whether the NSG settings of the Application Gateway subnet allow outbound public and private
traffic, so that a connection can be made. Check the document page that's provided in step 3a to learn
more about how to create NSG rules.
c. Check the user-defined routes (UDR) settings of Application Gateway and the backend server's subnet
for any routing anomalies. Make sure the UDR isn't directing the traffic away from the backend subnet.
For example, check for routes to network virtual appliances or default routes being advertised to the
Application Gateway subnet via Azure ExpressRoute and/or VPN.
d. To check the effective routes and rules for a network adapter, you can use the following PowerShell
commands:
4. If you don't find any issues with NSG or UDR, check your backend server for application-related issues
that are preventing clients from establishing a TCP session on the ports configured. A few things to check:
a. Open a command prompt (Win+R -> cmd), enter netstat , and select Enter.
b. Check whether the server is listening on the port that's configured. For example:
c. If it's not listening on the configured port, check your web server settings. For example: site bindings in
IIS, server block in NGINX and virtual host in Apache.
d. Check your OS firewall settings to make sure that incoming traffic to the port is allowed.
HTTP status code mismatch
Message: Status code of the backend's HTTP response did not match the probe setting. Expected:
{HTTPStatusCode0} Received:{HTTPStatusCode1}.
Cause: After the TCP connection has been established and a TLS handshake is done (if TLS is enabled),
Application Gateway will send the probe as an HTTP GET request to the backend server. As described earlier, the
default probe will be to <protocol>://127.0.0.1:<port>/, and it considers response status codes in the rage 200
through 399 as Healthy. If the server returns any other status code, it will be marked as Unhealthy with this
message.
Solution: Depending on the backend server's response code, you can take the following steps. A few of the
common status codes are listed here:
ERRO R A C T IO N S
Probe status code mismatch: Received 401 Check whether the backend server requires authentication.
Application Gateway probes can't pass credentials for
authentication. Either allow "HTTP 401" in a probe status
code match or probe to a path where the server doesn't
require authentication.
Probe status code mismatch: Received 403 Access forbidden. Check whether access to the path is
allowed on the backend server.
Probe status code mismatch: Received 404 Page not found. Check whether the host name path is
accessible on the backend server. Change the host name or
path parameter to an accessible value.
Probe status code mismatch: Received 405 The probe requests for Application Gateway use the HTTP
GET method. Check whether your server allows this method.
Probe status code mismatch: Received 500 Internal server error. Check the backend server's health and
whether the services are running.
Probe status code mismatch: Received 503 Service unavailable. Check the backend server's health and
whether the services are running.
Or, if you think the response is legitimate and you want Application Gateway to accept other status codes as
Healthy, you can create a custom probe. This approach is useful in situations where the backend website needs
authentication. Because the probe requests don't carry any user credentials, they will fail, and an HTTP 401
status code will be returned by the backend server.
To create a custom probe, follow these steps.
HTTP response body mismatch
Message: Body of the backend's HTTP response did not match the probe setting. Received response body does
not contain {string}.
Cause: When you create a custom probe, you have an option to mark a backend server as Healthy by matching
a string from the response body. For example, you can configure Application Gateway to accept "unauthorized"
as a string to match. If the backend server response for the probe request contains the string unauthorized , it
will be marked as Healthy. Otherwise, it will be marked as Unhealthy with this message.
Solution: To resolve this issue, follow these steps:
1. Access the backend server locally or from a client machine on the probe path, and check the response
body.
2. Verify that the response body in the Application Gateway custom probe configuration matches what's
configured.
3. If they don't match, change the probe configuration so that is has the correct string value to accept.
Learn more about Application Gateway probe matching.
NOTE
For all TLS related error messages, to learn more about SNI behavior and differences between the v1 and v2 SKU, check
the TLS overview page.
For example:
If the output doesn't show the complete chain of the certificate being returned, export the certificate again with
the complete chain, including the root certificate. Configure that certificate on your backend server.
CONNECTED(00000188)\
depth=0 OU = Domain Control Validated, CN = \*.example.com\
verify error:num=20:unable to get local issuer certificate\
verify return:1\
depth=0 OU = Domain Control Validated, CN = \*.example.com\
verify error:num=21:unable to verify the first certificate\
verify return:1\
\-\-\-\
Certificate chain\
0 s:/OU=Domain Control Validated/CN=*.example.com\
i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy
Secure Certificate Authority - G2\
\-----BEGIN CERTIFICATE-----\
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
\-----END CERTIFICATE-----
2. From the properties displayed, find the CN of the certificate and enter the same in the host name field of
the http settings. If that's not the desired host name for your website, you must get a certificate for that
domain or enter the correct host name in the custom probe or HTTP setting configuration.
Backend certificate is invalid
Message: Backend certificate is invalid. Current date is not within the "Valid from" and "Valid to" date range on
the certificate.
Cause: Every certificate comes with a validity range, and the HTTPS connection won't be secure unless the
server's TLS/SSL certificate is valid. The current data must be within the valid from and valid to range. If it's
not, the certificate is considered invalid, and that will create a security issue in which Application Gateway marks
the backend server as Unhealthy.
Solution: If your TLS/SSL certificate has expired, renew the certificate with your vendor and update the server
settings with the new certificate. If it's a self-signed certificate, you must generate a valid certificate and upload
the root certificate to the Application Gateway HTTP settings. To do that, follow these steps:
1. Open your Application Gateway HTTP settings in the portal.
2. Select the setting that has the expired certificate, select Add Cer tificate , and open the new certificate
file.
3. Remove the old certificate by using the Delete icon next to the certificate, and then select Save .
Certificate verification failed
Message: The validity of the backend certificate could not be verified. To find out the reason, check OpenSSL
diagnostics for the message associated with error code {errorCode}
Cause: This error occurs when Application Gateway can't verify the validity of the certificate.
Solution: To resolve this issue, verify that the certificate on your server was created properly. For example, you
can use OpenSSL to verify the certificate and its properties and then try reuploading the certificate to the
Application Gateway HTTP settings.
This behavior can occur for one or more of the following reasons:
1. The NSG on the Application Gateway subnet is blocking inbound access to ports 65503-65534 (v1 SKU) or
65200-65535 (v2 SKU) from “Internet."
2. The UDR on the Application Gateway subnet is set to the default route (0.0.0.0/0) and the next hop is not
specified as "Internet."
3. The default route is advertised by an ExpressRoute/VPN connection to a virtual network over BGP.
4. The custom DNS server is configured on a virtual network that can't resolve public domain names.
5. Application Gateway is in an Unhealthy state.
Solution:
1. Check whether your NSG is blocking access to the ports 65503-65534 (v1 SKU) or 65200-65535 (v2
SKU) from Internet :
a. On the Application Gateway Over view tab, select the Vir tual Network/Subnet link.
b. On the Subnets tab of your virtual network, select the subnet where Application Gateway has been
deployed.
c. Check whether any NSG is configured.
d. If an NSG is configured, search for that NSG resource on the Search tab or under All resources .
e. In the Inbound Rules section, add an inbound rule to allow destination port range 65503-65534 for
v1 SKU or 65200-65535 v2 SKU with the Source set as Any or Internet .
f. Select Save and verify that you can view the backend as Healthy. Alternatively, you can do that through
PowerShell/CLI.
2. Check whether your UDR has a default route (0.0.0.0/0) with the next hop not set as Internet :
a. Follow steps 1a and 1b to determine your subnet.
b. Check whether there's any UDR configured. If there is, search for the resource on the search bar or
under All resources .
c. Check whether there are any default routes (0.0.0.0/0) with the next hop not set as Internet . If the
setting is either Vir tual Appliance or Vir tual Network Gateway , you must make sure that your
virtual appliance or the on-premises device can properly route the packet back to the internet destination
without modifying the packet.
d. Otherwise, change the next hop to Internet , select Save , and verify the backend health.
3. Default route advertised by the ExpressRoute/VPN connection to the virtual network over BGP:
a. If you have an ExpressRoute/VPN connection to the virtual network over BGP, and if you are advertising
a default route, you must make sure that the packet is routed back to the internet destination without
modifying it. You can verify by using the Connection Troubleshoot option in the Application Gateway
portal.
b. Choose the destination manually as any internet-routable IP address like 1.1.1.1. Set the destination
port as anything, and verify the connectivity.
c. If the next hop is virtual network gateway, there might be a default route advertised over ExpressRoute
or VPN.
4. If there's a custom DNS server configured on the virtual network, verify that the server (or servers) can
resolve public domains. Public domain name resolution might be required in scenarios where Application
Gateway must reach out to external domains like OCSP servers or to check the certificate’s revocation
status.
5. To verify that Application Gateway is healthy and running, go to the Resource Health option in the
portal and verify that the state is Healthy . If you see an Unhealthy or Degraded state, contact support.
Next steps
Learn more about Application Gateway diagnostics and logging.
Create Application Gateway custom error pages
3/5/2021 • 2 minutes to read • Edit Online
Application Gateway allows you to create custom error pages instead of displaying default error pages. You can
use your own branding and layout using a custom error page.
For example, you can define your own maintenance page if your web application isn't reachable. Or, you can
create an unauthorized access page if a malicious request is sent to a web application.
Custom error pages are supported for the following two scenarios:
Maintenance page - This custom error page is sent instead of a 502 bad gateway page. It's shown when
Application Gateway has no backend to route traffic to. For example, when there's scheduled maintenance or
when an unforeseen issue effects backend pool access.
Unauthorized access page - This custom error page is sent instead of a 403 unauthorized access page. It's
shown when the Application Gateway WAF detects malicious traffic and blocks it.
If an error originates from the backend servers, then it's passed along unmodified back to the caller. A custom
error page isn't displayed. Application gateway can display a custom error page when a request can't reach the
backend.
Custom error pages can be defined at the global level and the listener level:
Global level - the error page applies to traffic for all the web applications deployed on that application
gateway.
Listener level - the error page is applied to traffic received on that listener.
Both - the custom error page defined at the listener level overrides the one set at global level.
To create a custom error page, you must have:
an HTTP response status code.
the corresponding location for the error page.
a publicly accessible Azure storage blob for the location.
an *.htm or *.html extension type.
The size of the error page must be less than 1 MB. If there are images linked in the error page, they must be
either publicly accessible absolute URLs or base64 encoded image inline in the custom error page. Relative links
with images in the same blob location are currently not supported.
After you specify an error page, the application gateway downloads it from the storage blob location and saves
it to the local application gateway cache. Then the error page is served directly from the application gateway. To
modify an existing custom error page, you must point to a different blob location in the application gateway
configuration. The application gateway doesn't periodically check the blob location to fetch new versions.
Portal configuration
1. Navigate to Application Gateway in the portal and choose an application gateway.
2. Click Listeners and navigate to a particular listener where you want to specify an error page.
3. Configure a custom error page for a 403 WAF error or a 502 maintenance page at the listener level.
NOTE
Creating global level custom error pages from the Azure portal is currently not supported.
4. Specify a publicly accessible blob URL for a given error status code and click Save . The Application
Gateway is now configured with the custom error page.
Azure PowerShell configuration
You can use Azure PowerShell to configure a custom error page. For example, a global custom error page:
Next steps
For information about Application Gateway diagnostics, see Back-end health, diagnostic logs, and metrics for
Application Gateway.
Migrate Azure Application Gateway and Web
Application Firewall from v1 to v2
3/5/2021 • 9 minutes to read • Edit Online
Azure Application Gateway and Web Application Firewall (WAF) v2 is now available, offering additional features
such as autoscaling and availability-zone redundancy. However, existing v1 gateways aren't automatically
upgraded to v2. If you want to migrate from v1 to v2, follow the steps in this article.
There are two stages in a migration:
1. Migrate the configuration
2. Migrate the client traffic
This article covers configuration migration. Client traffic migration varies depending on your specific
environment. However, some high-level, general recommendations are provided.
Migration overview
An Azure PowerShell script is available that does the following:
Creates a new Standard_v2 or WAF_v2 gateway in a virtual network subnet that you specify.
Seamlessly copies the configuration associated with the v1 Standard or WAF gateway to the newly created
Standard_V2 or WAF_V2 gateway.
Caveats\Limitations
The new v2 gateway has new public and private IP addresses. It isn't possible to move the IP addresses
associated with the existing v1 gateway seamlessly to v2. However, you can allocate an existing (unallocated)
public or private IP address to the new v2 gateway.
You must provide an IP address space for another subnet within your virtual network where your v1 gateway
is located. The script can't create the v2 gateway in any existing subnets that already have a v1 gateway.
However, if the existing subnet already has a v2 gateway, that may still work provided there's enough IP
address space.
If you have a network security group or user defined routes associated to the v2 gateway subnet, make sure
they adhere to the NSG requirements and UDR requirements for a successful migration
Virtual network service endpoint policies are currently not supported in an Application Gateway subnet.
To migrate a TLS/SSL configuration, you must specify all the TLS/SSL certs used in your v1 gateway.
If you have FIPS mode enabled for your V1 gateway, it won't be migrated to your new v2 gateway. FIPS mode
isn't supported in v2.
v2 doesn't support IPv6, so IPv6 enabled v1 gateways aren't migrated. If you run the script, it may not
complete.
If the v1 gateway has only a private IP address, the script creates a public IP address and a private IP address
for the new v2 gateway. v2 gateways currently don't support only private IP addresses.
Headers with names containing anything other than letters, digits, hyphens and underscores are not passed
to your application. This only applies to header names, not header values. This is a breaking change from v1.
AzureAppGwMigration.ps1
-resourceId <v1 application gateway Resource ID>
-subnetAddressRange <subnet space you want to use>
-appgwName <string to use to append>
-sslCertificates <comma-separated SSLCert objects as above>
-trustedRootCertificates <comma-separated Trusted Root Cert objects as above>
-privateIpAddress <private IP string>
-publicIpResourceId <public IP name string>
-validateMigration -enableAutoScale
subnetAddressRange: [String]: Required - This is the IP address space that you've allocated
(or want to allocate) for a new subnet that contains your new v2 gateway. This must be specified in
the CIDR notation. For example: 10.0.0.0/24. You don't need to create this subnet in advance. The
script creates it for you if it doesn't exist.
appgwName: [String]: Optional . This is a string you specify to use as the name for the new
Standard_v2 or WAF_v2 gateway. If this parameter isn't supplied, the name of your existing v1
gateway will be used with the suffix _v2 appended.
sslCer tificates: [PSApplicationGatewaySslCer tificate]: Optional . A comma-separated list of
PSApplicationGatewaySslCertificate objects that you create to represent the TLS/SSL certs from
your v1 gateway must be uploaded to the new v2 gateway. For each of your TLS/SSL certs
configured for your Standard v1 or WAF v1 gateway, you can create a new
PSApplicationGatewaySslCertificate object via the New-AzApplicationGatewaySslCertificate
command shown here. You need the path to your TLS/SSL Cert file and the password.
This parameter is only optional if you don't have HTTPS listeners configured for your v1 gateway
or WAF. If you have at least one HTTPS listener setup, you must specify this parameter.
You can pass in $mySslCert1, $mySslCert2 (comma-separated) in the previous example as values
for this parameter in the script.
trustedRootCer tificates: [PSApplicationGatewayTrustedRootCer tificate]: Optional . A
comma-separated list of PSApplicationGatewayTrustedRootCertificate objects that you create to
represent the Trusted Root certificates for authentication of your backend instances from your v2
gateway.
$certFilePath = ".\rootCA.cer"
$trustedCert = New-AzApplicationGatewayTrustedRootCertificate -Name "trustedCert1" -
CertificateFile $certFilePath
AzureAppGWMigration.ps1 `
-resourceId /subscriptions/8b1d0fea-8d57-4975-adfb-
308f1f4d12aa/resourceGroups/MyResourceGroup/providers/Microsoft.Network/applicationGateways/myv1appga
teway `
-subnetAddressRange 10.0.0.0/24 `
-appgwname "MynewV2gw" `
-sslCertificates $mySslCert1,$mySslCert2 `
-trustedRootCertificates $trustedCert `
-privateIpAddress "10.0.0.1" `
-publicIpResourceId "/subscriptions/8b1d0fea-8d57-4975-adfb-
308f1f4d12aa/resourceGroups/MyResourceGroup/providers/Microsoft.Network/publicIPAddresses/MyPublicIP"
`
-validateMigration -enableAutoScale
Common questions
Are there any limitations with the Azure PowerShell script to migrate the configuration from v1 to v2?
Yes. See Caveats/Limitations.
Is this article and the Azure PowerShell script applicable for Application Gateway WAF product as well?
Yes.
Does the Azure PowerShell script also switch over the traffic from my v1 gateway to the newly created v2
gateway?
No. The Azure PowerShell script only migrates the configuration. Actual traffic migration is your responsibility
and in your control.
Is the new v2 gateway created by the Azure PowerShell script sized appropriately to handle all of the traffic
that is currently served by my v1 gateway?
The Azure PowerShell script creates a new v2 gateway with an appropriate size to handle the traffic on your
existing v1 gateway. Autoscaling is disabled by default, but you can enable AutoScaling when you run the script.
I configured my v1 gateway to send logs to Azure storage. Does the script replicate this configuration for v2
as well?
No. The script doesn't replicate this configuration for v2. You must add the log configuration separately to the
migrated v2 gateway.
Does this script support certificates uploaded to Azure KeyVault ?
No. Currently the script does not support certificates in KeyVault. However, this is being considered for a future
version.
I ran into some issues with using this script. How can I get help?
You can contact Azure Support under the topic "Configuration and Setup/Migrate to V2 SKU". Learn more about
Azure support here.
Next steps
Learn about Application Gateway v2
Annotations for Application Gateway Ingress
Controller
3/5/2021 • 3 minutes to read • Edit Online
Introductions
The Kubernetes Ingress resource can be annotated with arbitrary key/value pairs. AGIC relies on annotations to
program Application Gateway features, which are not configurable via the Ingress YAML. Ingress annotations are
applied to all HTTP setting, backend pools, and listeners derived from an ingress resource.
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-bkprefix
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/backend-path-prefix: "/test/"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 80
In the example above, we have defined an ingress resource named go-server-ingress-bkprefix with an
annotation appgw.ingress.kubernetes.io/backend-path-prefix: "/test/" . The annotation tells application
gateway to create an HTTP setting, which will have a path prefix override for the path /hello to /test/ .
NOTE
In the above example we have only one rule defined. However, the annotations are applicable to the entire ingress
resource, so if a user had defined multiple rules, the backend path prefix would be set up for each of the paths specified.
Thus, if a user wants different rules with different path prefixes (even for the same service) they would need to define
different ingress resources.
TLS Redirect
Application Gateway can be configured to automatically redirect HTTP URLs to their HTTPS counterparts. When
this annotation is present and TLS is properly configured, Kubernetes Ingress controller will create a routing rule
with a redirection configuration and apply the changes to your Application Gateway. The redirect created will be
HTTP 301 Moved Permanently .
Usage
appgw.ingress.kubernetes.io/ssl-redirect: "true"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-redirect
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- www.contoso.com
secretName: testsecret-tls
rules:
- host: www.contoso.com
http:
paths:
- backend:
serviceName: websocket-repeater
servicePort: 80
Connection Draining
connection-draining : This annotation allows users to specify whether to enable connection draining.
connection-draining-timeout : This annotation allows users to specify a timeout after which Application Gateway
will terminate the requests to the draining backend endpoint.
Usage
appgw.ingress.kubernetes.io/connection-draining: "true"
appgw.ingress.kubernetes.io/connection-draining-timeout: "60"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-drain
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/connection-draining: "true"
appgw.ingress.kubernetes.io/connection-draining-timeout: "60"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 80
appgw.ingress.kubernetes.io/cookie-based-affinity: "true"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-affinity
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/cookie-based-affinity: "true"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 80
Request Timeout
This annotation allows to specify the request timeout in seconds after which Application Gateway will fail the
request if response is not received.
Usage
appgw.ingress.kubernetes.io/request-timeout: "20"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-timeout
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/request-timeout: "20"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 80
Use Private IP
This annotation allows us to specify whether to expose this endpoint on Private IP of Application Gateway.
NOTE
Application Gateway doesn't support multiple IPs on the same port (example: 80/443). Ingress with annotation
appgw.ingress.kubernetes.io/use-private-ip: "false" and another with
appgw.ingress.kubernetes.io/use-private-ip: "true" on HTTP will cause AGIC to fail in updating the
Application Gateway.
For Application Gateway that doesn't have a private IP, Ingresses with
appgw.ingress.kubernetes.io/use-private-ip: "true" will be ignored. This will reflected in the controller logs and
ingress events for those ingresses with NoPrivateIP warning.
Usage
appgw.ingress.kubernetes.io/use-private-ip: "true"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-timeout
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/use-private-ip: "true"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 80
Backend Protocol
This annotation allows us to specify the protocol that Application Gateway should use while talking to the Pods.
Supported Protocols: http , https
NOTE
While self-signed certificates are supported on Application Gateway, currently, AGIC only support https when Pods
are using certificate signed by a well-known CA.
Make sure to not use port 80 with HTTPS and port 443 with HTTP on the Pods.
Usage
appgw.ingress.kubernetes.io/backend-protocol: "https"
Example
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: go-server-ingress-timeout
namespace: test-ag
annotations:
kubernetes.io/ingress.class: azure/application-gateway
appgw.ingress.kubernetes.io/backend-protocol: "https"
spec:
rules:
- http:
paths:
- path: /hello/
backend:
serviceName: go-server-service
servicePort: 443
What is Azure Resource Manager?
3/26/2021 • 6 minutes to read • Edit Online
Azure Resource Manager is the deployment and management service for Azure. It provides a management layer
that enables you to create, update, and delete resources in your Azure account. You use management features,
like access control, locks, and tags, to secure and organize your resources after deployment.
To learn about Azure Resource Manager templates (ARM templates), see the template deployment overview.
All capabilities that are available in the portal are also available through PowerShell, Azure CLI, REST APIs, and
client SDKs. Functionality initially released through APIs will be represented in the portal within 180 days of
initial release.
Terminology
If you're new to Azure Resource Manager, there are some terms you might not be familiar with.
resource - A manageable item that is available through Azure. Virtual machines, storage accounts, web
apps, databases, and virtual networks are examples of resources. Resource groups, subscriptions,
management groups, and tags are also examples of resources.
resource group - A container that holds related resources for an Azure solution. The resource group
includes those resources that you want to manage as a group. You decide which resources belong in a
resource group based on what makes the most sense for your organization. See Resource groups.
resource provider - A service that supplies Azure resources. For example, a common resource provider is
Microsoft.Compute , which supplies the virtual machine resource. Microsoft.Storage is another common
resource provider. See Resource providers and types.
Resource Manager template - A JavaScript Object Notation (JSON) file that defines one or more
resources to deploy to a resource group, subscription, management group, or tenant. The template can be
used to deploy the resources consistently and repeatedly. See Template deployment overview.
declarative syntax - Syntax that lets you state "Here is what I intend to create" without having to write the
sequence of programming commands to create it. The Resource Manager template is an example of
declarative syntax. In the file, you define the properties for the infrastructure to deploy to Azure. See Template
deployment overview.
Understand scope
Azure provides four levels of scope: management groups, subscriptions, resource groups, and resources. The
following image shows an example of these layers.
You apply management settings at any of these levels of scope. The level you select determines how widely the
setting is applied. Lower levels inherit settings from higher levels. For example, when you apply a policy to the
subscription, the policy is applied to all resource groups and resources in your subscription. When you apply a
policy on the resource group, that policy is applied to the resource group and all its resources. However, another
resource group doesn't have that policy assignment.
You can deploy templates to tenants, management groups, subscriptions, or resource groups.
Resource groups
There are some important factors to consider when defining your resource group:
All the resources in your resource group should share the same lifecycle. You deploy, update, and delete
them together. If one resource, such as a server, needs to exist on a different deployment cycle it should
be in another resource group.
Each resource can exist in only one resource group.
You can add or remove a resource to a resource group at any time.
You can move a resource from one resource group to another group. For more information, see Move
resources to new resource group or subscription.
The resources in a resource group can be located in different regions than the resource group.
When creating a resource group, you need to provide a location for that resource group. You may be
wondering, "Why does a resource group need a location? And, if the resources can have different
locations than the resource group, why does the resource group location matter at all?" The resource
group stores metadata about the resources. When you specify a location for the resource group, you're
specifying where that metadata is stored. For compliance reasons, you may need to ensure that your data
is stored in a particular region.
If the resource group's region is temporarily unavailable, you can't update resources in the resource
group because the metadata is unavailable. The resources in other regions will still function as expected,
but you can't update them. For more information about building reliable applications, see Designing
reliable Azure applications.
A resource group can be used to scope access control for administrative actions. To manage a resource
group, you can assign Azure Policies, Azure roles, or resource locks.
You can apply tags to a resource group. The resources in the resource group don't inherit those tags.
A resource can connect to resources in other resource groups. This scenario is common when the two
resources are related but don't share the same lifecycle. For example, you can have a web app that
connects to a database in a different resource group.
When you delete a resource group, all resources in the resource group are also deleted. For information
about how Azure Resource Manager orchestrates those deletions, see Azure Resource Manager resource
group and resource deletion.
You can deploy up to 800 instances of a resource type in each resource group. Some resource types are
exempt from the 800 instance limit. For more information, see resource group limits.
Some resources can exist outside of a resource group. These resources are deployed to the subscription,
management group, or tenant. Only specific resource types are supported at these scopes.
To create a resource group, you can use the portal, PowerShell, Azure CLI, or an ARM template.
This article describes the structure of an Azure Resource Manager template (ARM template). It presents the
different sections of a template and the properties that are available in those sections.
This article is intended for users who have some familiarity with ARM templates. It provides detailed
information about the structure of the template. For a step-by-step tutorial that guides you through the process
of creating a template, see Tutorial: Create and deploy your first ARM template. To learn about ARM templates
through a guided set of modules on Microsoft Learn, see Deploy and manage resources in Azure by using ARM
templates.
Template format
In its simplest structure, a template has the following elements:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "",
"apiProfile": "",
"parameters": { },
"variables": { },
"functions": [ ],
"resources": [ ],
"outputs": { }
}
Each element has properties you can set. This article describes the sections of the template in greater detail.
Parameters
In the parameters section of the template, you specify which values you can input when deploying the
resources. You're limited to 256 parameters in a template. You can reduce the number of parameters by using
objects that contain multiple properties.
The available properties for a parameter are:
"parameters": {
"<parameter-name>" : {
"type" : "<type-of-parameter-value>",
"defaultValue": "<default-value-of-parameter>",
"allowedValues": [ "<array-of-allowed-values>" ],
"minValue": <minimum-value-for-int>,
"maxValue": <maximum-value-for-int>,
"minLength": <minimum-length-for-string-or-array>,
"maxLength": <maximum-length-for-string-or-array-parameters>,
"metadata": {
"description": "<description-of-the parameter>"
}
}
}
Variables
In the variables section, you construct values that can be used throughout your template. You don't need to
define variables, but they often simplify your template by reducing complex expressions. The format of each
variable matches one of the data types.
The following example shows the available options for defining a variable:
"variables": {
"<variable-name>": "<variable-value>",
"<variable-name>": {
<variable-complex-type-value>
},
"<variable-object-name>": {
"copy": [
{
"name": "<name-of-array-property>",
"count": <number-of-iterations>,
"input": <object-or-value-to-repeat>
}
]
},
"copy": [
{
"name": "<variable-array-name>",
"count": <number-of-iterations>,
"input": <object-or-value-to-repeat>
}
]
}
For information about using copy to create several values for a variable, see Variable iteration.
For examples of how to use variables, see Variables in ARM template.
Functions
Within your template, you can create your own functions. These functions are available for use in your template.
Typically, you define complicated expressions that you don't want to repeat throughout your template. You
create the user-defined functions from expressions and functions that are supported in templates.
When defining a user function, there are some restrictions:
The function can't access variables.
The function can only use parameters that are defined in the function. When you use the parameters function
within a user-defined function, you're restricted to the parameters for that function.
The function can't call other user-defined functions.
The function can't use the reference function.
Parameters for the function can't have default values.
"functions": [
{
"namespace": "<namespace-for-functions>",
"members": {
"<function-name>": {
"parameters": [
{
"name": "<parameter-name>",
"type": "<type-of-parameter-value>"
}
],
"output": {
"type": "<type-of-output-value>",
"value": "<function-return-value>"
}
}
}
}
],
EL EM EN T N A M E REQ UIRED DESC RIP T IO N
For examples of how to use custom functions, see User-defined functions in ARM template.
Resources
In the resources section, you define the resources that are deployed or updated.
You define resources with the following structure:
"resources": [
{
"condition": "<true-to-deploy-this-resource>",
"type": "<resource-provider-namespace/resource-type-name>",
"apiVersion": "<api-version-of-resource>",
"name": "<name-of-the-resource>",
"comments": "<your-reference-notes>",
"location": "<location-of-resource>",
"dependsOn": [
"<array-of-related-resource-names>"
],
"tags": {
"<tag-name1>": "<tag-value1>",
"<tag-name2>": "<tag-value2>"
},
"sku": {
"name": "<sku-name>",
"tier": "<sku-tier>",
"size": "<sku-size>",
"family": "<sku-family>",
"capacity": <sku-capacity>
},
"kind": "<type-of-resource>",
"scope": "<target-scope-for-extension-resources>",
"copy": {
"name": "<name-of-copy-loop>",
"count": <number-of-iterations>,
"mode": "<serial-or-parallel>",
"batchSize": <number-to-deploy-serially>
},
"plan": {
"name": "<plan-name>",
"promotionCode": "<plan-promotion-code>",
"publisher": "<plan-publisher>",
"product": "<plan-product>",
"version": "<plan-version>"
},
"properties": {
"<settings-for-the-resource>",
"copy": [
{
"name": ,
"count": ,
"input": {}
}
]
},
"resources": [
"<array-of-child-resources>"
]
}
]
Outputs
In the outputs section, you specify values that are returned from deployment. Typically, you return values from
resources that were deployed.
The following example shows the structure of an output definition:
"outputs": {
"<output-name>": {
"condition": "<boolean-value-whether-to-output-value>",
"type": "<type-of-output-value>",
"value": "<output-value-expression>",
"copy": {
"count": <number-of-iterations>,
"input": <values-for-the-variable>
}
}
}
NOTE
To deploy templates with comments by using Azure CLI with version 2.3.0 or older, you must use the
--handle-extended-json-format switch.
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-10-01",
"name": "[variables('vmName')]", // to customize name, change it in variables
"location": "[parameters('location')]", //defaults to resource group location
"dependsOn": [ /* storage account and network interface must be deployed first */
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
In Visual Studio Code, the Azure Resource Manager Tools extension can automatically detect an ARM template
and change the language mode. If you see Azure Resource Manager Template at the bottom-right corner of
Visual Studio Code, you can use the inline comments. The inline comments are no longer marked as invalid.
Metadata
You can add a metadata object almost anywhere in your template. Resource Manager ignores the object, but
your JSON editor may warn you that the property isn't valid. In the object, define the properties you need.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"comments": "This template was developed for demonstration purposes.",
"author": "Example Name"
},
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
When deploying the template through the portal, the text you provide in the description is automatically used as
a tip for that parameter.
For resources , add a comments element or a metadata object. The following example shows both a comments
element and a metadata object.
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"name": "[concat('storage', uniqueString(resourceGroup().id))]",
"comments": "Storage account used to store VM disks",
"location": "[parameters('location')]",
"metadata": {
"comments": "These tags are needed for policy compliance."
},
"tags": {
"Dept": "[parameters('deptName')]",
"Environment": "[parameters('environment')]"
},
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {}
}
]
"outputs": {
"hostname": {
"type": "string",
"value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]",
"metadata": {
"comments": "Return the fully qualified domain name"
}
},
Multi-line strings
You can break a string into multiple lines. For example, see the location property and one of the comments in
the following JSON example.
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-10-01",
"name": "[variables('vmName')]", // to customize name, change it in variables
"location": "[
parameters('location')
]", //defaults to resource group location
/*
storage account and network interface
must be deployed first
*/
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
],
NOTE
To deploy templates with multi-line strings by using Azure CLI with version 2.3.0 or older, you must use the
--handle-extended-json-format switch.
Next steps
To view complete templates for many different types of solutions, see the Azure Quickstart Templates.
For details about the functions you can use from within a template, see ARM template functions.
To combine several templates during deployment, see Using linked and nested templates when deploying
Azure resources.
For recommendations about creating templates, see ARM template best practices.
For answers to common questions, see Frequently asked questions about ARM templates.