Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a536233

Browse files
committedFeb 5, 2018
new internal redirection tutorial
1 parent 195e039 commit a536233

File tree

5 files changed

+542
-0
lines changed

5 files changed

+542
-0
lines changed
 

‎articles/application-gateway/TOC.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
## Configure external redirection
4646
### [Azure PowerShell](tutorial-external-site-redirect-cli.md)
4747
### [Azure CLI](tutorial-external-site-redirect-powershell.md)
48+
## Configure internal redirection
49+
### [Azure PowerShell](tutorial-internal-site-redirect-cli.md)
50+
### [Azure CLI](tutorial-internal-site-redirect-powershell.md)
4851
## Configure web apps as backend pool members
4952
### [Azure PowerShell](application-gateway-web-app-powershell.md)
5053
## Configure health probes
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
---
2+
title: Create an application gateway with internal redirection - Azure CLI | Microsoft Docs
3+
description: Learn how to create an application gateway that redirects internal web traffic to the appropriate pool using the Azure CLI.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: tysonn
8+
9+
ms.service: application-gateway
10+
ms.devlang: na
11+
ms.topic: article
12+
ms.tgt_pltfrm: na
13+
ms.workload: infrastructure-services
14+
ms.date: 01/24/2018
15+
ms.author: davidmu
16+
17+
---
18+
# Create an application gateway with internal redirection using the Azure CLI
19+
20+
You can use the Azure CLI to configure [web traffic redirection](application-gateway-multi-site-overview.md) when you create an [application gateway](application-gateway-introduction.md). In this tutorial, you create 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*.
21+
22+
In this article, you learn how to:
23+
24+
> [!div class="checklist"]
25+
> * Set up the network
26+
> * Create an application gateway
27+
> * Add listeners and redirection rule
28+
> * Create a virtual machine scale set with the backend pool
29+
> * Create a CNAME record in your domain
30+
31+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
32+
33+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
34+
35+
If you choose to install and use the CLI locally, this quickstart requires that you are running the Azure CLI version 2.0.4 or later. To find the version, run `az --version`. If you need to install or upgrade, see [Install Azure CLI 2.0](/cli/azure/install-azure-cli).
36+
37+
## Create a resource group
38+
39+
A resource group is a logical container into which Azure resources are deployed and managed. Create a resource group using [az group create](/cli/azure/group#create).
40+
41+
The following example creates a resource group named *myResourceGroupAG* in the *eastus* location.
42+
43+
```azurecli-interactive
44+
az group create --name myResourceGroupAG --location eastus
45+
```
46+
47+
## Create network resources
48+
49+
Create the virtual network named *myVNet* and the subnet named *myAGSubnet* using [az network vnet create](/cli/azure/network/vnet#az_net). You can then add the subnet named *myBackendSubnet* that's needed by the backend pool of servers using [az network vnet subnet create](/cli/azure/network/vnet/subnet#az_network_vnet_subnet_create). Create the public IP address named *myAGPublicIPAddress* using [az network public-ip create](/cli/azure/public-ip#az_network_public_ip_create).
50+
51+
```azurecli-interactive
52+
az network vnet create \
53+
--name myVNet \
54+
--resource-group myResourceGroupAG \
55+
--location eastus \
56+
--address-prefix 10.0.0.0/16 \
57+
--subnet-name myAGSubnet \
58+
--subnet-prefix 10.0.1.0/24
59+
az network vnet subnet create \
60+
--name myBackendSubnet \
61+
--resource-group myResourceGroupAG \
62+
--vnet-name myVNet \
63+
--address-prefix 10.0.2.0/24
64+
az network public-ip create \
65+
--resource-group myResourceGroupAG \
66+
--name myAGPublicIPAddress
67+
```
68+
69+
## Create the application gateway
70+
71+
You can use [az network application-gateway create](/cli/azure/application-gateway#create) to create the application gateway named *myAppGateway*. When you create an application gateway using the Azure CLI, you specify configuration information, such as capacity, sku, and HTTP settings. The application gateway is assigned to *myAGSubnet* and *myAGPublicIPAddress* that you previously created.
72+
73+
```azurecli-interactive
74+
az network application-gateway create \
75+
--name myAppGateway \
76+
--location eastus \
77+
--resource-group myResourceGroupAG \
78+
--vnet-name myVNet \
79+
--subnet myAGsubnet \
80+
--capacity 2 \
81+
--sku Standard_Medium \
82+
--http-settings-cookie-based-affinity Disabled \
83+
--frontend-port 80 \
84+
--http-settings-port 80 \
85+
--http-settings-protocol Http \
86+
--public-ip-address myAGPublicIPAddress
87+
```
88+
89+
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:
90+
91+
- *appGatewayBackendPool* - An application gateway must have at least one backend address pool.
92+
- *appGatewayBackendHttpSettings* - Specifies that port 80 and an HTTP protocol is used for communication.
93+
- *appGatewayHttpListener* - The default listener associated with *appGatewayBackendPool*.
94+
- *appGatewayFrontendIP* - Assigns *myAGPublicIPAddress* to *appGatewayHttpListener*.
95+
- *rule1* - The default routing rule that is associated with *appGatewayHttpListener*.
96+
97+
98+
## Add listeners and rules
99+
100+
A listener is required to enable the application gateway to route traffic appropriately to the backend pool. In this tutorial, you create two listeners for your two domains. In this example, listeners are created for the domains of *www.contoso.com* and *www.contoso.org*.
101+
102+
Add the backend listeners that are needed to route traffic using [az network application-gateway http-listener create](/cli/azure/application-gateway#az_network_application_gateway_http_listener_create).
103+
104+
```azurecli-interactive
105+
az network application-gateway http-listener create \
106+
--name contosoComListener \
107+
--frontend-ip appGatewayFrontendIP \
108+
--frontend-port appGatewayFrontendPort \
109+
--resource-group myResourceGroupAG \
110+
--gateway-name myAppGateway \
111+
--host-name www.contoso.com
112+
az network application-gateway http-listener create \
113+
--name contosoOrgListener \
114+
--frontend-ip appGatewayFrontendIP \
115+
--frontend-port appGatewayFrontendPort \
116+
--resource-group myResourceGroupAG \
117+
--gateway-name myAppGateway \
118+
--host-name www.contoso.org
119+
```
120+
121+
### Add the redirection configuration
122+
123+
Add the redirection configuration that sends traffic from *www.consoto.org* to the listener for *www.contoso.com* in the application gateway using [az network application-gateway redirect-config create](/cli/azure/network/application-gateway/redirect-config#az_network_application_gateway_redirect_config_create).
124+
125+
```azurecli-interactive
126+
az network application-gateway redirect-config create \
127+
--name orgToCom \
128+
--gateway-name myAppGateway \
129+
--resource-group myResourceGroupAG \
130+
--type Permanent \
131+
--target-listener contosoComListener \
132+
--include-path true \
133+
--include-query-string true
134+
```
135+
136+
### Add routing rules
137+
138+
Rules are processed in the order in which they are created, and traffic is directed using the first rule that matches the URL sent to the application gateway. The default basic rule that was created is not needed in this tutorial. In this example, you create two new rules named *contosoComRule* and *contosoOrgRule* and delete the default rule that was created. You can add the rules using [az network application-gateway rule create](/cli/azure/application-gateway#az_network_application_gateway_rule_create).
139+
140+
```azurecli-interactive
141+
az network application-gateway rule create \
142+
--gateway-name myAppGateway \
143+
--name contosoComRule \
144+
--resource-group myResourceGroupAG \
145+
--http-listener contosoComListener \
146+
--rule-type Basic \
147+
--address-pool appGatewayBackendPool
148+
az network application-gateway rule create \
149+
--gateway-name myAppGateway \
150+
--name contosoOrgRule \
151+
--resource-group myResourceGroupAG \
152+
--http-listener contosoOrgListener \
153+
--rule-type Basic \
154+
--redirect-config orgToCom
155+
az network application-gateway rule delete \
156+
--gateway-name myAppGateway \
157+
--name rule1 \
158+
--resource-group myResourceGroupAG
159+
```
160+
161+
## Create virtual machine scale sets
162+
163+
In this example, you create a virtual machine scale set that supports the default backend pool that was created. The scale set that you create is named *myvmss* and contains two virtual machine instances on which you install NGINX.
164+
165+
```azurecli-interactive
166+
az vmss create \
167+
--name myvmss \
168+
--resource-group myResourceGroupAG \
169+
--image UbuntuLTS \
170+
--admin-username azureuser \
171+
--admin-password Azure123456! \
172+
--instance-count 2 \
173+
--vnet-name myVNet \
174+
--subnet myBackendSubnet \
175+
--vm-sku Standard_DS2 \
176+
--upgrade-policy-mode Automatic \
177+
--app-gateway myAppGateway \
178+
--backend-pool-name appGatewayBackendPool
179+
```
180+
181+
### Install NGINX
182+
183+
```azurecli-interactive
184+
az vmss extension set \
185+
--publisher Microsoft.Azure.Extensions \
186+
--version 2.0 \
187+
--name CustomScript \
188+
--resource-group myResourceGroupAG \
189+
--vmss-name myvmss \
190+
--settings '{ "fileUris": ["https://raw.githubusercontent.com/davidmu1/samplescripts/master/install_nginx.sh"],
191+
"commandToExecute": "./install_nginx.sh" }'
192+
```
193+
194+
## Create CNAME record in your domain
195+
196+
After the application gateway is created with its public IP address, you can get the DNS address and use it to create a CNAME record in your domain. You can use [az network public-ip show](/cli/azure/network/public-ip#az_network_public_ip_show) to get the DNS address of the application gateway. Copy the *fqdn* value of the DNSSettings and use it as the value of the CNAME record that you create. The use of A-records is not recommended because the VIP may change when the application gateway is restarted.
197+
198+
```azurecli-interactive
199+
az network public-ip show \
200+
--resource-group myResourceGroupAG \
201+
--name myAGPublicIPAddress \
202+
--query [dnsSettings.fqdn] \
203+
--output tsv
204+
```
205+
206+
## Test the application gateway
207+
208+
Enter your domain name into the address bar of your browser. Such as, http://www.contoso.com.
209+
210+
![Test contoso site in application gateway](./media/tutorial-internal-site-redirect-cli/application-gateway-nginxtest.png)
211+
212+
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.
213+
214+
## Next steps
215+
216+
In this tutorial, you learned how to:
217+
218+
> [!div class="checklist"]
219+
> * Set up the network
220+
> * Create an application gateway
221+
> * Add listeners and redirection rule
222+
> * Create a virtual machine scale set with the backend pool
223+
> * Create a CNAME record in your domain
224+
225+
> [!div class="nextstepaction"]
226+
> [Learn more about what you can do with application gateway](./application-gateway-introduction.md)
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
---
2+
title: Create an application gateway with internal redirection - Azure PowerShell | Microsoft Docs
3+
description: Learn how to create an application gateway that redirects internal web traffic to the appropriate backend pool of servers using Azure Powershell.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: tysonn
8+
9+
ms.service: application-gateway
10+
ms.devlang: na
11+
ms.topic: article
12+
ms.tgt_pltfrm: na
13+
ms.workload: infrastructure-services
14+
ms.date: 01/23/2018
15+
ms.author: davidmu
16+
17+
---
18+
# Create an application gateway with internal redirection using Azure PowerShell
19+
20+
You can use Azure Powershell to configure [web traffic redirection](application-gateway-multi-site-overview.md) when you create an [application gateway](application-gateway-introduction.md). 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*.
21+
22+
In this article, you learn how to:
23+
24+
> [!div class="checklist"]
25+
> * Set up the network
26+
> * Create an application gateway
27+
> * Add listeners and redirection rule
28+
> * Create a virtual machine scale set with the backend pool
29+
> * Create a CNAME record in your domain
30+
31+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
32+
33+
[!INCLUDE [cloud-shell-powershell.md](../../includes/cloud-shell-powershell.md)]
34+
35+
If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 3.6 or later. To find the version, run ` Get-Module -ListAvailable AzureRM` . If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azurerm-ps). If you are running PowerShell locally, you also need to run `Login-AzureRmAccount` to create a connection with Azure.
36+
37+
## Create a resource group
38+
39+
A resource group is a logical container into which Azure resources are deployed and managed. Create an Azure resource group using [New-AzureRmResourceGroup](/powershell/module/azurerm.resources/new-azurermresourcegroup).
40+
41+
```azurepowershell-interactive
42+
New-AzureRmResourceGroup -Name myResourceGroupAG -Location eastus
43+
```
44+
45+
## Create network resources
46+
47+
Create the subnet configurations for *myBackendSubnet* and *myAGSubnet* using [New-AzureRmVirtualNetworkSubnetConfig](/powershell/module/azurerm.network/new-azurermvirtualnetworksubnetconfig). Create the virtual network named *myVNet* using [New-AzureRmVirtualNetwork](/powershell/module/azurerm.network/new-azurermvirtualnetwork) with the subnet configurations. And finally, create the public IP address named *myAGPublicIPAddress* using [New-AzureRmPublicIpAddress](/powershell/module/azurerm.network/new-azurermpublicipaddress). These resources are used to provide network connectivity to the application gateway and its associated resources.
48+
49+
```azurepowershell-interactive
50+
$backendSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
51+
-Name myBackendSubnet `
52+
-AddressPrefix 10.0.1.0/24
53+
$agSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
54+
-Name myAGSubnet `
55+
-AddressPrefix 10.0.2.0/24
56+
$vnet = New-AzureRmVirtualNetwork `
57+
-ResourceGroupName myResourceGroupAG `
58+
-Location eastus `
59+
-Name myVNet `
60+
-AddressPrefix 10.0.0.0/16 `
61+
-Subnet $backendSubnetConfig, $agSubnetConfig
62+
$pip = New-AzureRmPublicIpAddress `
63+
-ResourceGroupName myResourceGroupAG `
64+
-Location eastus `
65+
-Name myAGPublicIPAddress `
66+
-AllocationMethod Dynamic
67+
```
68+
69+
## Create an application gateway
70+
71+
### Create the IP configurations and frontend port
72+
73+
Associate *myAGSubnet* that you previously created to the application gateway using [New-AzureRmApplicationGatewayIPConfiguration](/powershell/module/azurerm.network/new-azurermapplicationgatewayipconfiguration). Assign *myAGPublicIPAddress* to the application gateway using [New-AzureRmApplicationGatewayFrontendIPConfig](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendipconfig). And then you can create the HTTP port using [New-AzureRmApplicationGatewayFrontendPort](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendport).
74+
75+
```azurepowershell-interactive
76+
$vnet = Get-AzureRmVirtualNetwork `
77+
-ResourceGroupName myResourceGroupAG `
78+
-Name myVNet
79+
$subnet=$vnet.Subnets[0]
80+
$pip = Get-AzureRmPublicIpAddress `
81+
-ResourceGroupName myResourceGroupAG `
82+
-Name myAGPublicIPAddress
83+
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration `
84+
-Name myAGIPConfig `
85+
-Subnet $subnet
86+
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig `
87+
-Name myAGFrontendIPConfig `
88+
-PublicIPAddress $pip
89+
$frontendPort = New-AzureRmApplicationGatewayFrontendPort `
90+
-Name myFrontendPort `
91+
-Port 80
92+
```
93+
94+
### Create the backend pool and settings
95+
96+
Create a backend pool named *contosoPool* for the application gateway using [New-AzureRmApplicationGatewayBackendAddressPool](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendaddresspool). Configure the settings for the backend pool using [New-AzureRmApplicationGatewayBackendHttpSettings](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendhttpsettings).
97+
98+
```azurepowershell-interactive
99+
$contosoPool = New-AzureRmApplicationGatewayBackendAddressPool `
100+
-Name contosoPool
101+
$poolSettings = New-AzureRmApplicationGatewayBackendHttpSettings `
102+
-Name myPoolSettings `
103+
-Port 80 `
104+
-Protocol Http `
105+
-CookieBasedAffinity Enabled `
106+
-RequestTimeout 120
107+
```
108+
109+
### Create the first listener and rule
110+
111+
A listener is required to enable the application gateway to route traffic appropriately to the backend pool. In this tutorial, you create two listeners for your two domains. In this example, listeners are created for the domains of *www.contoso.com* and *www.contoso.org*.
112+
113+
Create the first listener named *contosoComListener* using [New-AzureRmApplicationGatewayHttpListener](/powershell/module/azurerm.network/new-azurermapplicationgatewayhttplistener) 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 *contosoComRule* using [New-AzureRmApplicationGatewayRequestRoutingRule](/powershell/module/azurerm.network/new-azurermapplicationgatewayrequestroutingrule).
114+
115+
```azurepowershell-interactive
116+
$contosoComlistener = New-AzureRmApplicationGatewayHttpListener `
117+
-Name contosoComListener `
118+
-Protocol Http `
119+
-FrontendIPConfiguration $fipconfig `
120+
-FrontendPort $frontendPort `
121+
-HostName "www.contoso.com"
122+
$frontendRule = New-AzureRmApplicationGatewayRequestRoutingRule `
123+
-Name contosoComRule `
124+
-RuleType Basic `
125+
-HttpListener $contosoComListener `
126+
-BackendAddressPool $contosoPool `
127+
-BackendHttpSettings $poolSettings
128+
```
129+
130+
### Create the application gateway
131+
132+
Now that you created the necessary supporting resources, specify parameters for the application gateway named *myAppGateway* using [New-AzureRmApplicationGatewaySku](/powershell/module/azurerm.network/new-azurermapplicationgatewaysku), and then create it using [New-AzureRmApplicationGateway](/powershell/module/azurerm.network/new-azurermapplicationgateway).
133+
134+
```azurepowershell-interactive
135+
$sku = New-AzureRmApplicationGatewaySku `
136+
-Name Standard_Medium `
137+
-Tier Standard `
138+
-Capacity 2
139+
$appgw = New-AzureRmApplicationGateway `
140+
-Name myAppGateway `
141+
-ResourceGroupName myResourceGroupAG `
142+
-Location eastus `
143+
-BackendAddressPools $contosoPool `
144+
-BackendHttpSettingsCollection $poolSettings `
145+
-FrontendIpConfigurations $fipconfig `
146+
-GatewayIpConfigurations $gipconfig `
147+
-FrontendPorts $frontendPort `
148+
-HttpListeners $contosoComListener `
149+
-RequestRoutingRules $frontendRule `
150+
-Sku $sku
151+
```
152+
153+
### Add the second listener
154+
155+
Add the listener named *contosoOrgListener* that's needed to redirect traffic using [Add-AzureRmApplicationGatewayHttpListener](/powershell/module/azurerm.network/add-azurermapplicationgatewayhttplistener).
156+
157+
```azurepowershell-interactive
158+
$appgw = Get-AzureRmApplicationGateway `
159+
-ResourceGroupName myResourceGroupAG `
160+
-Name myAppGateway
161+
$frontendPort = Get-AzureRmApplicationGatewayFrontendPort `
162+
-Name myFrontendPort `
163+
-ApplicationGateway $appgw
164+
$ipconfig = Get-AzureRmApplicationGatewayFrontendIPConfig `
165+
-Name myAGFrontendIPConfig `
166+
-ApplicationGateway $appgw
167+
Add-AzureRmApplicationGatewayHttpListener `
168+
-ApplicationGateway $appgw `
169+
-Name contosoOrgListener `
170+
-Protocol Http `
171+
-FrontendIPConfiguration $ipconfig `
172+
-FrontendPort $frontendPort `
173+
-HostName "www.contoso.org"
174+
Set-AzureRmApplicationGateway -ApplicationGateway $appgw
175+
```
176+
177+
### Add the redirection configuration
178+
179+
You can configure redirection for the listener using [Add-AzureRmApplicationGatewayRedirectConfiguration](/powershell/module/azurerm.network/add-azurermapplicationgatewayredirectconfiguration).
180+
181+
```azurepowershell-interactive
182+
$appgw = Get-AzureRmApplicationGateway `
183+
-ResourceGroupName myResourceGroupAG `
184+
-Name myAppGateway
185+
$contosoComlistener = Get-AzureRmApplicationGatewayHttpListener `
186+
-Name contosoComListener `
187+
-ApplicationGateway $appgw
188+
$contosoOrglistener = Get-AzureRmApplicationGatewayHttpListener `
189+
-Name contosoOrgListener `
190+
-ApplicationGateway $appgw
191+
Add-AzureRmApplicationGatewayRedirectConfiguration `
192+
-ApplicationGateway $appgw `
193+
-Name redirectOrgtoCom `
194+
-RedirectType Found `
195+
-TargetListener $contosoComListener `
196+
-IncludePath $true `
197+
-IncludeQueryString $true
198+
Set-AzureRmApplicationGateway -ApplicationGateway $appgw
199+
```
200+
201+
### Add the second routing rule
202+
203+
You can then associate the redirection configuration to a new rule named *contosoOrgRule* using [Add-AzureRmApplicationGatewayRequestRoutingRule](/powershell/module/azurerm.network/add-azurermapplicationgatewayrequestroutingrule).
204+
205+
```azurepowershell-interactive
206+
$appgw = Get-AzureRmApplicationGateway `
207+
-ResourceGroupName myResourceGroupAG `
208+
-Name myAppGateway
209+
$contosoOrglistener = Get-AzureRmApplicationGatewayHttpListener `
210+
-Name contosoOrgListener `
211+
-ApplicationGateway $appgw
212+
$redirectConfig = Get-AzureRmApplicationGatewayRedirectConfiguration `
213+
-Name redirectOrgtoCom `
214+
-ApplicationGateway $appgw
215+
Add-AzureRmApplicationGatewayRequestRoutingRule `
216+
-ApplicationGateway $appgw `
217+
-Name contosoOrgRule `
218+
-RuleType Basic `
219+
-HttpListener $contosoOrgListener `
220+
-RedirectConfiguration $redirectConfig
221+
Set-AzureRmApplicationGateway -ApplicationGateway $appgw
222+
```
223+
224+
## Create virtual machine scale set
225+
226+
In this example, you create a virtual machine scale set that supports the backend pool that you created. The scale set that you create is named *myvmss* and 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.
227+
228+
```azurepowershell-interactive
229+
$vnet = Get-AzureRmVirtualNetwork `
230+
-ResourceGroupName myResourceGroupAG `
231+
-Name myVNet
232+
$appgw = Get-AzureRmApplicationGateway `
233+
-ResourceGroupName myResourceGroupAG `
234+
-Name myAppGateway
235+
$backendPool = Get-AzureRmApplicationGatewayBackendAddressPool `
236+
-Name contosoPool `
237+
-ApplicationGateway $appgw
238+
$ipConfig = New-AzureRmVmssIpConfig `
239+
-Name myVmssIPConfig `
240+
-SubnetId $vnet.Subnets[1].Id `
241+
-ApplicationGatewayBackendAddressPoolsId $backendPool.Id
242+
$vmssConfig = New-AzureRmVmssConfig `
243+
-Location eastus `
244+
-SkuCapacity 2 `
245+
-SkuName Standard_DS2 `
246+
-UpgradePolicyMode Automatic
247+
Set-AzureRmVmssStorageProfile $vmssConfig `
248+
-ImageReferencePublisher MicrosoftWindowsServer `
249+
-ImageReferenceOffer WindowsServer `
250+
-ImageReferenceSku 2016-Datacenter `
251+
-ImageReferenceVersion latest
252+
Set-AzureRmVmssOsProfile $vmssConfig `
253+
-AdminUsername azureuser `
254+
-AdminPassword "Azure123456!" `
255+
-ComputerNamePrefix myvmss
256+
Add-AzureRmVmssNetworkInterfaceConfiguration `
257+
-VirtualMachineScaleSet $vmssConfig `
258+
-Name myVmssNetConfig `
259+
-Primary $true `
260+
-IPConfiguration $ipConfig
261+
New-AzureRmVmss `
262+
-ResourceGroupName myResourceGroupAG `
263+
-Name myvmss `
264+
-VirtualMachineScaleSet $vmssConfig
265+
```
266+
267+
### Install IIS
268+
269+
```azurepowershell-interactive
270+
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/davidmu1/samplescripts/master/appgatewayurl.ps1");
271+
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
272+
$vmss = Get-AzureRmVmss -ResourceGroupName myResourceGroupAG -VMScaleSetName myvmss
273+
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss `
274+
-Name "customScript" `
275+
-Publisher "Microsoft.Compute" `
276+
-Type "CustomScriptExtension" `
277+
-TypeHandlerVersion 1.8 `
278+
-Setting $publicSettings
279+
Update-AzureRmVmss `
280+
-ResourceGroupName myResourceGroupAG `
281+
-Name myvmss `
282+
-VirtualMachineScaleSet $vmss
283+
```
284+
285+
## Create CNAME record in your domain
286+
287+
After the application gateway is created with its public IP address, you can get the DNS address and use it to create a CNAME record in your domain. You can use [Get-AzureRmPublicIPAddress](/powershell/module/azurerm.network/get-azurermpublicipaddress) to get the DNS address of the application gateway. Copy the *fqdn* value of the DNSSettings and use it as the value of the CNAME record that you create. The use of A-records is not recommended because the VIP may change when the application gateway is restarted.
288+
289+
```azurepowershell-interactive
290+
Get-AzureRmPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
291+
```
292+
293+
## Test the application gateway
294+
295+
Enter your domain name into the address bar of your browser. Such as, http://www.contoso.com.
296+
297+
![Test contoso site in application gateway](./media/tutorial-internal-site-redirect-powershell/application-gateway-iistest.png)
298+
299+
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.
300+
301+
## Next steps
302+
303+
In this article, you learned how to:
304+
305+
> [!div class="checklist"]
306+
> * Set up the network
307+
> * Create an application gateway
308+
> * Add listeners and redirection rule
309+
> * Create a virtual machine scale set with the backend pools
310+
> * Create a CNAME record in your domain
311+
312+
> [!div class="nextstepaction"]
313+
> [Learn more about what you can do with application gateway](./application-gateway-introduction.md)

0 commit comments

Comments
 (0)
Please sign in to comment.