Create an Application Gateway With Path-Based Routing Rules
Create virtual machines
In this example, you create three virtual machines to be used as backend servers for the application gateway. You also install IIS on the virtual machines to verify that the application gateway works as expected.
- Sign in to the Azure portal at https://portal.azure.com.
- On the Azure portal, select Create a resource.
- Select Windows Server 2016 Datacenter in the Popular list.
- Enter these values for the virtual machine:
- Subscription – Select your subscription.
- Resource group, select Create new, and then type myResourceGroupAG.
- Virtual machine name:Â myVM1
- Region:Â (US) East US
- Username: Type a user name
- Password: Type a password
- Select Next:Disks.
- Select Next:Networking
- For Virtual network, select Create new and then type 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.
- myBackendSubnet for the first subnet name
- 10.0.1.0/24Â – for the subnet address space.
- myAGSubnet – for the second subnet name.
- 10.0.0.0/24Â – for the subnet address space.
- Select OK.
- Ensure that under Subnet, myBackendSubnet is selected for the subnet, and then select Next: Management.
- Select Disable to disable boot diagnostics.
- Select Review + Create, review the settings on the summary page, and then select Create.
- Create two more virtual machines, myVM2 and myVM3 and place them in the MyVNet virtual network and the myBackendSubnet subnet.
Install IIS
- Open the interactive shell and make sure that it’s set to PowerShell.
- Run the following command to install IIS on the virtual machine:
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/Azure/azure-docs-powershell-samples/master/application-gateway/iis/appgatewayurl.ps1"); "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" } Set-AzVMExtension ` -ResourceGroupName myResourceGroupAG ` -Location eastus ` -ExtensionName IIS ` -VMName myVM1 ` -Publisher Microsoft.Compute ` -ExtensionType CustomScriptExtension ` -TypeHandlerVersion 1.4 ` -Settings $publicSettings
- Install IIS on the other virtual machines using the steps that you just finished. Use myVM2 and myVM3 for VMName values in Set-AzVMExtension.
Create an application gateway
- Select Create a resource on the left menu of the Azure portal.
- Select Networking and then select Application Gateway in the Featured list.
Basics tab
- On the Basics tab, enter these values for the following application gateway settings:
- Subscription: Select your subscription.
- Resource group: Select myResourceGroupAG for the resource group.
- Application gateway name: Type myAppGateway for the name of the application gateway.
- Region – Select East US.
- Under Configure virtual network, select myVNet for the name of the virtual network.
- Select myAGSubnet for the subnet.
- Accept the default values for the other settings and then select Next: Frontends.
Frontends tab
- On the Frontends tab, verify Frontend IP address type is set to Public.
- Select Add new for the Public IP address and enter myAGPublicIPAddress for the public IP address name, and then select OK.
- 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.
- On the Backends tab, select Add a backend pool.
- 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.
- Under Target type, select Virtual machine from the drop-down list.
- Under Target select the network interface for myVM1.
- Select Add.
- Repeat to add an Images backend pool with myVM2 as the target, and a Video backend pool with myVM3 as the target.
- Select Add to save the backend pool configuration and return to the Backends tab.
- 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.
- Select Add a routing rule in the Routing rules column.
- In the Add a routing rule window that opens, enter myRoutingRule for the Rule name.
- 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.
- Port: 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.
- On the Backend targets tab, select myBackendPool for the Backend target.
- For the HTTP setting, select Add new to create a new HTTP setting. The HTTP setting will determine the behavior of the routing rule.
- 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.
- Under Path-based routing, select Add multiple targets to create a path-based rule.
- For Path, type /images/*.
- For Target name, type Images.
- For HTTP setting, select myHTTPSetting
- For Backend target, select Images.
- Select Add to save the path rule and return to the Add a routing rule tab.
- Repeat to add another rule for Video.
- Select Add to add the routing rule and return to the Configuration tab.
- 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.
Test the application gateway
- Select All resources, and then select myAppGateway.
- 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.
- Change the URL to http://<ip-address>:8080/images/test.htm, replacing <ip-address> with the public IP address of myAppGateway, and you should see something like the following example:
The listener on port 8080 routes this request to the Images backend pool. - Change the URL to http://<ip-address>:8080/video/test.htm, replacing <ip-address> with the public IP address of myAppGateway, and you should see something like the following example:
The listener on port 8080 routes this request to the Video backend pool.
Tag:Azure