Skip to content

Commit 1191828

Browse files
committed
Merge latest changes from main branch
2 parents ae7f281 + fc985d5 commit 1191828

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

articles/application-gateway/tutorial-url-redirect-powershell.md

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ ms.date: 03/24/2021
88
ms.author: mbender
99
ms.topic: how-to
1010
ms.custom: devx-track-azurepowershell
11-
#Customer intent: As an IT administrator, I want to use Azure PowerShell to set up URL path redirection of web traffic to specific pools of servers so I can ensure my customers have access to the information they need.
1211
# Customer intent: As an IT administrator, I want to configure an application gateway with URL path-based redirection using PowerShell, so that I can efficiently route web traffic to specific server pools based on URL patterns and enhance the user experience.
1312
---
1413

1514
# Create an application gateway with URL path-based redirection using Azure PowerShell
1615

17-
You can use Azure PowerShell to configure [URL-based routing rules](./url-route-overview.md) when you create an [application gateway](./overview.md). In this article, you create backend pools using [virtual machine scale sets](/azure/virtual-machine-scale-sets/overview). You then create URL routing rules that make sure web traffic is redirected to the appropriate backend pool.
16+
You can use Azure PowerShell to configure [URL-based routing rules](./url-route-overview.md) when you create an [application gateway](./overview.md). In this tutorial, you create backend pools using [virtual machine scale sets](/azure/virtual-machine-scale-sets/overview). You then create URL routing rules that redirect web traffic to the appropriate backend pool based on the request URL path.
1817

19-
In this article, you learn how to:
18+
In this tutorial, you learn how to:
2019

21-
* Set up the network
22-
* Create an application gateway
23-
* Add listeners and routing rules
24-
* Create virtual machine scale sets for backend pools
20+
> [!div class="checklist"]
21+
> * Set up the network infrastructure
22+
> * Create an application gateway with path-based routing
23+
> * Add listeners and routing rules for URL redirection
24+
> * Create virtual machine scale sets for backend pools
25+
> * Test the application gateway routing and redirection functionality
2526
2627
The following example shows site traffic coming from both ports 8080 and 8081 and being directed to the same backend pools:
2728

@@ -47,7 +48,10 @@ New-AzResourceGroup -Name myResourceGroupAG -Location eastus
4748

4849
## Create network resources
4950

50-
Create the subnet configurations for *myBackendSubnet* and *myAGSubnet* using [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig). Create the virtual network named *myVNet* using [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) with the subnet configurations. And finally, create the public IP address named *myAGPublicIPAddress* using [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress). These resources are used to provide network connectivity to the application gateway and its associated resources.
51+
Create the subnet configurations for *myBackendSubnet* and *myAGSubnet* using [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig). Create the virtual network named *myVNet* using [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) with the subnet configurations. Finally, create the public IP address named *myAGPublicIPAddress* using [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress). These resources provide network connectivity to the application gateway and its associated resources.
52+
53+
> [!IMPORTANT]
54+
> The application gateway subnet (*myAGSubnet*) can contain only application gateways. No other resources are allowed in this subnet.
5155
5256
```azurepowershell-interactive
5357
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
@@ -82,7 +86,7 @@ In this section, you create resources that support the application gateway, and
8286

8387
### Create the IP configurations and frontend port
8488

85-
Associate *myAGSubnet* that you previously created to the application gateway using [New-AzApplicationGatewayIPConfiguration](/powershell/module/az.network/new-azapplicationgatewayipconfiguration). Assign *myAGPublicIPAddress* to the application gateway using [New-AzApplicationGatewayFrontendIPConfig](/powershell/module/az.network/new-azapplicationgatewayfrontendipconfig). And then you can create the HTTP port using [New-AzApplicationGatewayFrontendPort](/powershell/module/az.network/new-azapplicationgatewayfrontendport).
89+
Associate *myAGSubnet* that you previously created to the application gateway using [New-AzApplicationGatewayIPConfiguration](/powershell/module/az.network/new-azapplicationgatewayipconfiguration). Assign *myAGPublicIPAddress* to the application gateway using [New-AzApplicationGatewayFrontendIPConfig](/powershell/module/az.network/new-azapplicationgatewayfrontendipconfig). Then create the HTTP port using [New-AzApplicationGatewayFrontendPort](/powershell/module/az.network/new-azapplicationgatewayfrontendport).
8690

8791
```azurepowershell-interactive
8892
$vnet = Get-AzVirtualNetwork `
@@ -126,7 +130,7 @@ $poolSettings = New-AzApplicationGatewayBackendHttpSettings `
126130

127131
### Create the default listener and rule
128132

129-
A listener is required to enable the application gateway to route traffic appropriately to a backend pool. In this article, you create multiple listeners. The first basic listener expects traffic at the root URL. The other listeners expect traffic at specific URLs, such as `http://52.168.55.24:8080/images/` or `http://52.168.55.24:8081/video/`.
133+
A listener is required to enable the application gateway to route traffic appropriately to backend pools. In this tutorial, you create multiple listeners for different routing scenarios. The first basic listener expects traffic at the root URL. The other listeners expect traffic at specific URL paths, such as `http://52.168.55.24:8080/images/` or `http://52.168.55.24:8081/video/`.
130134

131135
Create a listener named *defaultListener* using [New-AzApplicationGatewayHttpListener](/powershell/module/az.network/new-azapplicationgatewayhttplistener) with the frontend configuration and frontend port that you previously created. A rule is required for the listener to know which backend pool to use for incoming traffic. Create a basic rule named *rule1* using [New-AzApplicationGatewayRequestRoutingRule](/powershell/module/az.network/new-azapplicationgatewayrequestroutingrule).
132136

@@ -171,7 +175,7 @@ New-AzApplicationGateway `
171175

172176
### Add backend pools and ports
173177

174-
You can add backend pools to your application gateway by using [Add-AzApplicationGatewayBackendAddressPool](/powershell/module/az.network/add-azapplicationgatewaybackendaddresspool). In this example, *imagesBackendPool* and *videoBackendPool* are created. You add the frontend port for the pools using [Add-AzApplicationGatewayFrontendPort](/powershell/module/az.network/add-azapplicationgatewayfrontendport). You then submit the changes to the application gateway using [Set-AzApplicationGateway](/powershell/module/az.network/set-azapplicationgateway).
178+
You can add backend pools to your application gateway using [Add-AzApplicationGatewayBackendAddressPool](/powershell/module/az.network/add-azapplicationgatewaybackendaddresspool). In this example, *imagesBackendPool* and *videoBackendPool* are created for routing specific content types. You add frontend ports for the pools using [Add-AzApplicationGatewayFrontendPort](/powershell/module/az.network/add-azapplicationgatewayfrontendport). Submit the changes to the application gateway using [Set-AzApplicationGateway](/powershell/module/az.network/set-azapplicationgateway).
175179

176180
```azurepowershell-interactive
177181
$appgw = Get-AzApplicationGateway `
@@ -240,7 +244,7 @@ Set-AzApplicationGateway -ApplicationGateway $appgw
240244

241245
### Add the default URL path map
242246

243-
URL path maps make sure that specific URLs are routed to specific backend pools. You can create the URL path maps named *imagePathRule* and *videoPathRule* using [New-AzApplicationGatewayPathRuleConfig](/powershell/module/az.network/new-azapplicationgatewaypathruleconfig) and [Add-AzApplicationGatewayUrlPathMapConfig](/powershell/module/az.network/add-azapplicationgatewayurlpathmapconfig).
247+
URL path maps ensure that specific URLs are routed to specific backend pools. You can create URL path maps named *imagePathRule* and *videoPathRule* using [New-AzApplicationGatewayPathRuleConfig](/powershell/module/az.network/new-azapplicationgatewaypathruleconfig) and [Add-AzApplicationGatewayUrlPathMapConfig](/powershell/module/az.network/add-azapplicationgatewayurlpathmapconfig).
244248

245249
```azurepowershell-interactive
246250
$appgw = Get-AzApplicationGateway `
@@ -388,9 +392,10 @@ Set-AzApplicationGateway -ApplicationGateway $appgw
388392

389393
## Create virtual machine scale sets
390394

391-
In this example, you create three virtual machine scale sets that support the three backend pools that you created. The scale sets that you create are named *myvmss1*, *myvmss2*, and *myvmss3*. Each scale set contains two virtual machine instances on which you install IIS. You assign the scale set to the backend pool when you configure the IP settings.
395+
In this example, you create three virtual machine scale sets that support the three backend pools that you created. The scale sets are named *myvmss1*, *myvmss2*, and *myvmss3*. Each scale set contains two virtual machine instances on which you install IIS. You assign the scale set to the backend pool when you configure the IP settings.
392396

393-
Replace \<username> and \<password> with your own values before you run the script.
397+
> [!IMPORTANT]
398+
> Replace `<username>` and `<password>` with your own values before running the script. Use a strong password that meets Azure's security requirements.
394399
395400
```azurepowershell-interactive
396401
$vnet = Get-AzVirtualNetwork `
@@ -466,6 +471,8 @@ for ($i=1; $i -le 3; $i++)
466471

467472
### Install IIS
468473

474+
The following script installs IIS on the virtual machines in each scale set and configures them to display different content based on which backend pool they serve.
475+
469476
```azurepowershell-interactive
470477
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/Azure/azure-docs-powershell-samples/master/application-gateway/iis/appgatewayurl.ps1");
471478
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
@@ -490,23 +497,31 @@ for ($i=1; $i -le 3; $i++)
490497

491498
## Test the application gateway
492499

493-
You can use [Get-AzPublicIPAddress](/powershell/module/az.network/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. Such as, `http://52.168.55.24`, `http://52.168.55.24:8080/images/test.htm`, `http://52.168.55.24:8080/video/test.htm`, or `http://52.168.55.24:8081/images/test.htm`.
500+
Although IIS isn't required to create the application gateway, you installed it in this tutorial to verify if Azure successfully created the application gateway. Use IIS to test the application gateway:
494501

495-
```azurepowershell-interactive
496-
Get-AzPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
497-
```
502+
1. Run [Get-AzPublicIPAddress](/powershell/module/az.network/get-azpublicipaddress) to get the public IP address of the application gateway:
503+
504+
```azurepowershell-interactive
505+
Get-AzPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
506+
```
507+
508+
2. Copy the public IP address, and then paste it into the address bar of your browser. For example:
509+
- `http://52.168.55.24` (base URL)
510+
- `http://52.168.55.24:8080/images/test.htm` (images path)
511+
- `http://52.168.55.24:8080/video/test.htm` (video path)
512+
- `http://52.168.55.24:8081/images/test.htm` (redirection test)
498513

499514
![Test base URL in application gateway](./media/tutorial-url-redirect-powershell/application-gateway-iistest.png)
500515

501-
Change the URL to http://&lt;ip-address&gt;:8080/images/test.htm, substituting your IP address for &lt;ip-address&gt;, and you should see something like the following example:
516+
Change the URL to `http://<ip-address>:8080/images/test.htm`, substituting your IP address for `<ip-address>`, and you should see something like the following example:
502517

503518
![Test images URL in application gateway](./media/tutorial-url-redirect-powershell/application-gateway-iistest-images.png)
504519

505-
Change the URL to http://&lt;ip-address&gt;:8080/video/test.htm, substituting your IP address for &lt;ip-address&gt;, and you should see something like the following example:
520+
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:
506521

507522
![Test video URL in application gateway](./media/tutorial-url-redirect-powershell/application-gateway-iistest-video.png)
508523

509-
Now, change the URL to http://&lt;ip-address&gt;:8081/images/test.htm, substituting your IP address for &lt;ip-address&gt;, and you should see traffic redirected back to the images backend pool at http://&lt;ip-address&gt;:8080/images.
524+
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`.
510525

511526
## Clean up resources
512527

0 commit comments

Comments
 (0)