Application Gateway (Layer 7) in Azure - Commands & Configuration
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Network/applicationGateways",
"apiVersion": "2023-02-01",
"name": "myAppGateway",
"location": "eastus",
"properties": {
"sku": {
"name": "Standard_v2",
"tier": "Standard_v2",
"capacity": 2
},
"gatewayIPConfigurations": [
{
"name": "appGatewayIpConfig",
"properties": {
"subnet": {
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
}
}
}
],
"frontendIPConfigurations": [
{
"name": "appGatewayFrontendIP",
"properties": {
"publicIPAddress": {
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP"
}
}
}
],
"frontendPorts": [
{
"name": "appGatewayFrontendPort",
"properties": {
"port": 80
}
}
],
"backendAddressPools": [
{
"name": "appGatewayBackendPool",
"properties": {
"backendAddresses": [
{ "ipAddress": "10.0.1.4" },
{ "ipAddress": "10.0.1.5" }
]
}
}
],
"backendHttpSettingsCollection": [
{
"name": "appGatewayBackendHttpSettings",
"properties": {
"port": 80,
"protocol": "Http",
"cookieBasedAffinity": "Disabled"
}
}
],
"httpListeners": [
{
"name": "appGatewayHttpListener",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(resourceId('Microsoft.Network/applicationGateways', 'myAppGateway'), '/frontendIPConfigurations/appGatewayFrontendIP')]"
},
"frontendPort": {
"id": "[concat(resourceId('Microsoft.Network/applicationGateways', 'myAppGateway'), '/frontendPorts/appGatewayFrontendPort')]"
},
"protocol": "Http"
}
}
],
"requestRoutingRules": [
{
"name": "rule1",
"properties": {
"ruleType": "Basic",
"httpListener": {
"id": "[concat(resourceId('Microsoft.Network/applicationGateways', 'myAppGateway'), '/httpListeners/appGatewayHttpListener')]"
},
"backendAddressPool": {
"id": "[concat(resourceId('Microsoft.Network/applicationGateways', 'myAppGateway'), '/backendAddressPools/appGatewayBackendPool')]"
},
"backendHttpSettings": {
"id": "[concat(resourceId('Microsoft.Network/applicationGateways', 'myAppGateway'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
}
}
}
]
}
}
]
}This JSON file is an Azure Resource Manager template that creates an Application Gateway named myAppGateway in the eastus region.
The sku defines the size and features of the gateway.
The gatewayIPConfigurations link the gateway to a subnet in a virtual network.
The frontendIPConfigurations set up a public IP address where users connect.
The frontendPorts define which port listens for web traffic (port 80 for HTTP).
The backendAddressPools list the IP addresses of servers that will receive the traffic.
The backendHttpSettingsCollection defines how to connect to backend servers.
The httpListeners listen for incoming requests on the frontend IP and port.
The requestRoutingRules connect listeners to backend pools, directing traffic properly.
az network application-gateway create --name myAppGateway --resource-group myResourceGroup --location eastus --sku Standard_v2 --capacity 2 --vnet-name myVnet --subnet mySubnet --public-ip-address myPublicIP--sku - Defines the size and features of the Application Gateway--capacity - Sets the number of instances for load balancing--public-ip-address - Assigns the public IP for user accessaz network application-gateway http-settings update --gateway-name myAppGateway --resource-group myResourceGroup --name appGatewayBackendHttpSettings --port 80 --protocol Http --cookie-based-affinity Disabled--port - Specifies the port to connect to backend servers--protocol - Sets the protocol used to communicate with backend serversaz network application-gateway rule create --gateway-name myAppGateway --resource-group myResourceGroup --name rule1 --http-listener appGatewayHttpListener --rule-type Basic --address-pool appGatewayBackendPool --http-settings appGatewayBackendHttpSettings
--rule-type - Defines the type of routing rule (Basic or Path-based)az network application-gateway show --name myAppGateway --resource-group myResourceGroup
If you remember nothing else from this pattern, remember: Application Gateway manages and routes web traffic securely and efficiently at the web (Layer 7) level.