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 8a5d441

Browse files
committedApr 17, 2018
more missing linked files
1 parent 0006e57 commit 8a5d441

File tree

6 files changed

+867
-0
lines changed

6 files changed

+867
-0
lines changed
 
Loading
Loading
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
---
2+
title: Quickstart - Direct web traffic with Azure Application Gateway - Azure CLI | Microsoft Docs
3+
description: Learn how use the Azure CLI to create an Azure Application Gateway that directs web traffic to virtual machines in a backend pool.
4+
services: application-gateway
5+
author: vhorne
6+
manager: jpconnock
7+
editor: ''
8+
tags: azure-resource-manager
9+
10+
ms.service: application-gateway
11+
ms.devlang: azurecli
12+
ms.topic: quickstart
13+
ms.workload: infrastructure-services
14+
ms.date: 02/14/2018
15+
ms.author: victorh
16+
ms.custom: mvc
17+
18+
---
19+
# Quickstart: Direct web traffic with Azure Application Gateway - Azure CLI
20+
21+
With Azure Application Gateway, you can direct your application web traffic to specific resources by assigning listeners to ports, creating rules, and adding resources to a backend pool.
22+
23+
This quickstart shows you how to use the Azure CLI to quickly create the application gateway with two virtual machines in its backend pool. You then test it to make sure it's working correctly.
24+
25+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
26+
27+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
28+
29+
If you choose to install and use the CLI locally, this quickstart requires that you run 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).
30+
31+
## Create a resource group
32+
33+
You need to always create resources in a resource group. Create a resource group using [az group create](/cli/azure/group#az_group_create).
34+
35+
The following example creates a resource group named *myResourceGroupAG* in the *eastus* location.
36+
37+
```azurecli-interactive
38+
az group create --name myResourceGroupAG --location eastus
39+
```
40+
41+
## Create network resources
42+
43+
You need to create a virtual network for the application gateway to be able to communicate with other resources. You can create a virtual network at the same time that you create the application gateway. Two subnets are created in this example: one for the application gateway, and the other for the virtual machines.
44+
45+
Create the virtual network and subnet using [az network vnet create](/cli/azure/vnet#az_vnet_create). Create the public IP address using [az network public-ip create](/cli/azure/public-ip#az_public_ip_create).
46+
47+
```azurecli-interactive
48+
az network vnet create \
49+
--name myVNet \
50+
--resource-group myResourceGroupAG \
51+
--location eastus \
52+
--address-prefix 10.0.0.0/16 \
53+
--subnet-name myAGSubnet \
54+
--subnet-prefix 10.0.1.0/24
55+
az network vnet subnet create \
56+
--name myBackendSubnet \
57+
--resource-group myResourceGroupAG \
58+
--vnet-name myVNet \
59+
--address-prefix 10.0.2.0/24
60+
az network public-ip create \
61+
--resource-group myResourceGroupAG \
62+
--name myAGPublicIPAddress
63+
```
64+
65+
## Create backend servers
66+
67+
In this example, you create two virtual machines to be used as backend servers for the application gateway.
68+
69+
### Create two virtual machines
70+
71+
You also install NGINX on the virtual machines to verify that the application gateway was successfully created. You can use a cloud-init configuration file to install NGINX and run a 'Hello World' Node.js app on a Linux virtual machine.
72+
73+
In your current shell, create a file named cloud-init.txt and copy and paste the following configuration into the shell. Make sure that you copy the whole cloud-init file correctly, especially the first line:
74+
75+
```yaml
76+
#cloud-config
77+
package_upgrade: true
78+
packages:
79+
- nginx
80+
- nodejs
81+
- npm
82+
write_files:
83+
- owner: www-data:www-data
84+
- path: /etc/nginx/sites-available/default
85+
content: |
86+
server {
87+
listen 80;
88+
location / {
89+
proxy_pass http://localhost:3000;
90+
proxy_http_version 1.1;
91+
proxy_set_header Upgrade $http_upgrade;
92+
proxy_set_header Connection keep-alive;
93+
proxy_set_header Host $host;
94+
proxy_cache_bypass $http_upgrade;
95+
}
96+
}
97+
- owner: azureuser:azureuser
98+
- path: /home/azureuser/myapp/index.js
99+
content: |
100+
var express = require('express')
101+
var app = express()
102+
var os = require('os');
103+
app.get('/', function (req, res) {
104+
res.send('Hello World from host ' + os.hostname() + '!')
105+
})
106+
app.listen(3000, function () {
107+
console.log('Hello world app listening on port 3000!')
108+
})
109+
runcmd:
110+
- service nginx restart
111+
- cd "/home/azureuser/myapp"
112+
- npm init
113+
- npm install express -y
114+
- nodejs index.js
115+
```
116+
117+
Create the network interfaces with [az network nic create](/cli/azure/network/nic#az_network_nic_create). Create the virtual machines with [az vm create](/cli/azure/vm#az_vm_create).
118+
119+
```azurecli-interactive
120+
for i in `seq 1 2`; do
121+
az network nic create \
122+
--resource-group myResourceGroupAG \
123+
--name myNic$i \
124+
--vnet-name myVNet \
125+
--subnet myBackendSubnet
126+
az vm create \
127+
--resource-group myResourceGroupAG \
128+
--name myVM$i \
129+
--nics myNic$i \
130+
--image UbuntuLTS \
131+
--admin-username azureuser \
132+
--generate-ssh-keys \
133+
--custom-data cloud-init.txt
134+
done
135+
```
136+
137+
## Create the application gateway
138+
139+
Create an application gateway using [az network application-gateway create](/cli/azure/application-gateway#az_application_gateway_create). When you create an application gateway using the Azure CLI, you specify configuration information, such as capacity, sku, and HTTP settings. The private IP addresses of the network interfaces are added as servers in the backend pool of the application gateway.
140+
141+
```azurecli-interactive
142+
address1=$(az network nic show --name myNic1 --resource-group myResourceGroupAG | grep "\"privateIpAddress\":" | grep -oE '[^ ]+$' | tr -d '",')
143+
address2=$(az network nic show --name myNic2 --resource-group myResourceGroupAG | grep "\"privateIpAddress\":" | grep -oE '[^ ]+$' | tr -d '",')
144+
az network application-gateway create \
145+
--name myAppGateway \
146+
--location eastus \
147+
--resource-group myResourceGroupAG \
148+
--capacity 2 \
149+
--sku Standard_Medium \
150+
--http-settings-cookie-based-affinity Enabled \
151+
--public-ip-address myAGPublicIPAddress \
152+
--vnet-name myVNet \
153+
--subnet myAGSubnet \
154+
--servers "$address1" "$address2"
155+
```
156+
157+
It may take up to 30 minutes for the application gateway to be created. After the application gateway is created, you can see these features of it:
158+
159+
- *appGatewayBackendPool* - An application gateway must have at least one backend address pool.
160+
- *appGatewayBackendHttpSettings* - Specifies that port 80 and an HTTP protocol is used for communication.
161+
- *appGatewayHttpListener* - The default listener associated with *appGatewayBackendPool*.
162+
- *appGatewayFrontendIP* - Assigns *myAGPublicIPAddress* to *appGatewayHttpListener*.
163+
- *rule1* - The default routing rule that is associated with *appGatewayHttpListener*.
164+
165+
## Test the application gateway
166+
167+
Installing NGINX is not required to create the application gateway, but you installed it in this quickstart to verify whether the application gateway was successfully created. To get the public IP address of the application gateway, use [az network public-ip show](/cli/azure/network/public-ip#az_network_public_ip_show). Copy the public IP address, and then paste it into the address bar of your browser.
168+
169+
```azurepowershell-interactive
170+
az network public-ip show \
171+
--resource-group myResourceGroupAG \
172+
--name myAGPublicIPAddress \
173+
--query [ipAddress] \
174+
--output tsv
175+
```
176+
177+
![Test application gateway](./media/quick-create-cli/application-gateway-nginxtest.png)
178+
179+
When you refresh the browser, you should see the name of the other VM appear.
180+
181+
## Clean up resources
182+
183+
First explore the resources that were created with the application gateway, and then when no longer needed, you can use the [az group delete](/cli/azure/group#az_group_delete) command to remove the resource group, application gateway, and all related resources.
184+
185+
```azurecli-interactive
186+
az group delete --name myResourceGroupAG
187+
```
188+
189+
## Next steps
190+
191+
> [!div class="nextstepaction"]
192+
> [Manage web traffic with an application gateway using the Azure CLI](./tutorial-manage-web-traffic-cli.md)
193+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
title: Quickstart - Direct web traffic with Azure Application Gateway - Azure portal | Microsoft Docs
3+
description: Learn how use the Azure portal to create an Azure Application Gateway that directs web traffic to virtual machines in a backend pool.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: ''
8+
tags: azure-resource-manager
9+
10+
ms.service: application-gateway
11+
ms.topic: quickstart
12+
ms.workload: infrastructure-services
13+
ms.date: 02/14/2018
14+
ms.author: davidmu
15+
ms.custom: mvc
16+
---
17+
# Quickstart: Direct web traffic with Azure Application Gateway - Azure portal
18+
19+
With Azure Application Gateway, you can direct your application web traffic to specific resources by assigning listeners to ports, creating rules, and adding resources to a backend pool.
20+
21+
This quickstart shows you how to use the Azure portal to quickly create the application gateway with two virtual machines in its backend pool. You then test it to make sure it's working correctly.
22+
23+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
24+
25+
## Log in to Azure
26+
27+
Log in to the Azure portal at [http://portal.azure.com](http://portal.azure.com)
28+
29+
## Create an application gateway
30+
31+
You need to create a virtual network for the application gateway to be able to communicate with other resources. You can create a virtual network at the same time that you create the application gateway. Two subnets are created in this example: one for the application gateway, and the other for the virtual machines.
32+
33+
1. Click **Create a resource** found on the upper left-hand corner of the Azure portal.
34+
2. Select **Networking** and then select **Application Gateway** in the Featured list.
35+
3. Enter these values for the application gateway:
36+
37+
- *myAppGateway* - for the name of the application gateway.
38+
- *myResourceGroupAG* - for the new resource group.
39+
40+
![Create new application gateway](./media/quick-create-portal/application-gateway-create.png)
41+
42+
4. Accept the default values for the other settings and then click **OK**.
43+
5. Click **Choose a virtual network** > **Create new**, and then enter these values for the virtual network:
44+
45+
- *myVNet* - for the name of the virtual network.
46+
- *10.0.0.0/16* - for the virtual network address space.
47+
- *myAGSubnet* - for the subnet name.
48+
- *10.0.0.0/24* - for the subnet address space.
49+
50+
![Create virtual network](./media/quick-create-portal/application-gateway-vnet.png)
51+
52+
6. Click **OK** to create the virtual network and subnet.
53+
6. Click **Choose a public IP address** > **Create new**, and then enter the name of the public IP address. In this example, the public IP address is named *myAGPublicIPAddress*. Accept the default values for the other settings and then click **OK**.
54+
8. Accept the default values for the listener configuration, leave the web application firewall disabled, and then click **OK**.
55+
9. Review the settings on the summary page, and then click **OK** to create the virtual network, the public IP address, and the application gateway. It may take up to 30 minutes for the application gateway to be created, wait until the deployment finishes successfully before moving on to the next section.
56+
57+
### Add a subnet
58+
59+
1. Click **All resources** in the left-hand menu, and then click **myVNet** from the resources list.
60+
2. Click **Subnets** > **Subnet**.
61+
62+
![Create subnet](./media/quick-create-portal/application-gateway-subnet.png)
63+
64+
3. Enter *myBackendSubnet* for the name of the subnet and then click **OK**.
65+
66+
## Create backend servers
67+
68+
In this example, you create two virtual machines to be used as backend servers for the application gateway.
69+
70+
### Create a virtual machine
71+
72+
1. Click **New**.
73+
2. Select **Compute** and then select **Windows Server 2016 Datacenter** in the Featured list.
74+
3. Enter these values for the virtual machine:
75+
76+
- *myVM* - for the name of the virtual machine.
77+
- *azureuser* - for the administrator user name.
78+
- *Azure123456!* for the password.
79+
- Select **Use existing**, and then select *myResourceGroupAG*.
80+
81+
4. Click **OK**.
82+
5. Select **DS1_V2** for the size of the virtual machine and then click **Select**.
83+
6. Make sure that **myVNet** is selected for the virtual network and the subnet is **myBackendSubnet**.
84+
7. Click **Disabled** to disable boot diagnostics.
85+
8. Click **OK**, review the settings on the summary page, and then click **Create**.
86+
87+
### Install IIS
88+
89+
You install IIS on the virtual machines to verify that the application gateway was successfully created.
90+
91+
1. Open the interactive shell and make sure that it is set to **PowerShell**.
92+
93+
![Install custom extension](./media/quick-create-portal/application-gateway-extension.png)
94+
95+
2. Run the following command to install IIS on the virtual machine:
96+
97+
```azurepowershell-interactive
98+
Set-AzureRmVMExtension `
99+
-ResourceGroupName myResourceGroupAG `
100+
-ExtensionName IIS `
101+
-VMName myVM `
102+
-Publisher Microsoft.Compute `
103+
-ExtensionType CustomScriptExtension `
104+
-TypeHandlerVersion 1.4 `
105+
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
106+
-Location EastUS
107+
```
108+
109+
3. Create a second virtual machine and install IIS using the steps that you just finished. Enter *myVM2* for its name and for VMName in Set-AzureRmVMExtension.
110+
111+
### Add backend servers
112+
113+
After you create the virtual machines, you need to add them to the backend pool in the application gateway.
114+
115+
1. Click **All resources** > **myAppGateway**.
116+
2. Click **Backend pools**. A default pool was automatically created with the application gateway. Click **appGatewayBackendPool**.
117+
3. Click **Add target** > **Virtual machine**, and then select *myVM*. Select **Add target** > **Virtual machine**, and then select *myVM2*.
118+
119+
![Add backend servers](./media/quick-create-portal/application-gateway-backend.png)
120+
121+
4. Click **Save**.
122+
123+
## Test the application gateway
124+
125+
Installing IIS is not required to create the application gateway, but you installed it in this quickstart to verify whether the application gateway was successfully created.
126+
127+
1. Find the public IP address for the application gateway on the Overview screen. Click **All resources** > **myAGPublicIPAddress**.
128+
129+
![Record application gateway public IP address](./media/quick-create-portal/application-gateway-record-ag-address.png)
130+
131+
2. Copy the public IP address, and then paste it into the address bar of your browser.
132+
133+
![Test application gateway](./media/quick-create-portal/application-gateway-iistest.png)
134+
135+
When you refresh the browser, you should see the name of the other VM appear.
136+
137+
## Clean up resources
138+
139+
First explore the resources that were created with the application gateway, and then when no longer needed, you can delete the resource group, application gateway, and all related resources. To do so, select the resource group that contains the application gateway and click **Delete**.
140+
141+
## Next steps
142+
143+
> [!div class="nextstepaction"]
144+
> [Manage web traffic with an application gateway using the Azure CLI](./tutorial-manage-web-traffic-cli.md)
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
title: Quickstart - Direct web traffic with Azure Application Gateway - Azure PowerShell | Microsoft Docs
3+
description: Learn how use Azure PowerShell to create an Azure Application Gateway that directs web traffic to virtual machines in a backend pool.
4+
services: application-gateway
5+
author: davidmu1
6+
manager: timlt
7+
editor: ''
8+
tags: azure-resource-manager
9+
10+
ms.service: application-gateway
11+
ms.devlang: azurepowershell
12+
ms.topic: quickstart
13+
ms.workload: infrastructure-services
14+
ms.date: 01/25/2018
15+
ms.author: davidmu
16+
ms.custom: mvc
17+
---
18+
19+
# Quickstart: Direct web traffic with Azure Application Gateway - Azure PowerShell
20+
21+
With Azure Application Gateway, you can direct your application web traffic to specific resources by assigning listeners to ports, creating rules, and adding resources to a backend pool.
22+
23+
This quickstart shows you how to use the Azure portal to quickly create the application gateway with two virtual machines in its backend pool. You then test it to make sure it's working correctly.
24+
25+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
26+
27+
[!INCLUDE [cloud-shell-powershell.md](../../includes/cloud-shell-powershell.md)]
28+
29+
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.
30+
31+
## Create a resource group
32+
33+
You need to always create resources in a resource group. Create an Azure resource group using [New-AzureRmResourceGroup](/powershell/module/azurerm.resources/new-azurermresourcegroup).
34+
35+
```azurepowershell-interactive
36+
New-AzureRmResourceGroup -Name myResourceGroupAG -Location eastus
37+
```
38+
39+
## Create network resources
40+
41+
You need to create a virtual network for the application gateway to be able to communicate with other resources. Two subnets are created in this example: one for the application gateway, and the other for the backend servers.
42+
43+
Create the subnet configurations using [New-AzureRmVirtualNetworkSubnetConfig](/powershell/module/azurerm.network/new-azurermvirtualnetworksubnetconfig). Create the virtual network using [New-AzureRmVirtualNetwork](/powershell/module/azurerm.network/new-azurermvirtualnetwork) with the subnet configurations. And finally, create the public IP address using [New-AzureRmPublicIpAddress](/powershell/module/azurerm.network/new-azurermpublicipaddress).
44+
45+
```azurepowershell-interactive
46+
$backendSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
47+
-Name myAGSubnet `
48+
-AddressPrefix 10.0.1.0/24
49+
$agSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
50+
-Name myBackendSubnet `
51+
-AddressPrefix 10.0.2.0/24
52+
New-AzureRmVirtualNetwork `
53+
-ResourceGroupName myResourceGroupAG `
54+
-Location eastus `
55+
-Name myVNet `
56+
-AddressPrefix 10.0.0.0/16 `
57+
-Subnet $backendSubnetConfig, $agSubnetConfig
58+
New-AzureRmPublicIpAddress `
59+
-ResourceGroupName myResourceGroupAG `
60+
-Location eastus `
61+
-Name myAGPublicIPAddress `
62+
-AllocationMethod Dynamic
63+
```
64+
## Create backend servers
65+
66+
In this example, you create two virtual machines to be used as backend servers for the application gateway.
67+
68+
You also install IIS on the virtual machines to verify that the application gateway was successfully created.
69+
70+
### Create two virtual machines
71+
72+
Create a network interface with [New-AzureRmNetworkInterface](/powershell/module/azurerm.network/new-azurermnetworkinterface). Create a virtual machine configuration with [New-AzureRmVMConfig](/powershell/module/azurerm.compute/new-azurermvmconfig). When you run the following commands, you are prompted for credentials. Enter *azureuser* for the user name and *Azure123456!* for the password. Create the virtual machine with [New-AzureRmVM](/powershell/module/azurerm.compute/new-azurermvm).
73+
74+
```azurepowershell-interactive
75+
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName myResourceGroupAG -Name myVNet
76+
$cred = Get-Credential
77+
for ($i=1; $i -le 2; $i++)
78+
{
79+
$nic = New-AzureRmNetworkInterface `
80+
-Name myNic$i `
81+
-ResourceGroupName myResourceGroupAG `
82+
-Location EastUS `
83+
-SubnetId $vnet.Subnets[1].Id
84+
$vm = New-AzureRmVMConfig `
85+
-VMName myVM$i `
86+
-VMSize Standard_DS2
87+
$vm = Set-AzureRmVMOperatingSystem `
88+
-VM $vm `
89+
-Windows `
90+
-ComputerName myVM$i `
91+
-Credential $cred
92+
$vm = Set-AzureRmVMSourceImage `
93+
-VM $vm `
94+
-PublisherName MicrosoftWindowsServer `
95+
-Offer WindowsServer `
96+
-Skus 2016-Datacenter `
97+
-Version latest
98+
$vm = Add-AzureRmVMNetworkInterface `
99+
-VM $vm `
100+
-Id $nic.Id
101+
$vm = Set-AzureRmVMBootDiagnostics `
102+
-VM $vm `
103+
-Disable
104+
New-AzureRmVM -ResourceGroupName myResourceGroupAG -Location EastUS -VM $vm
105+
Set-AzureRmVMExtension `
106+
-ResourceGroupName myResourceGroupAG `
107+
-ExtensionName IIS `
108+
-VMName myVM$i `
109+
-Publisher Microsoft.Compute `
110+
-ExtensionType CustomScriptExtension `
111+
-TypeHandlerVersion 1.4 `
112+
-SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}' `
113+
-Location EastUS
114+
}
115+
```
116+
117+
## Create an application gateway
118+
119+
### Create the IP configurations and frontend port
120+
121+
Use [New-AzureRmApplicationGatewayIPConfiguration](/powershell/module/azurerm.network/new-azurermapplicationgatewayipconfiguration) to create the configuration that associates the subnet that you previously created with the application gateway. Use [New-AzureRmApplicationGatewayFrontendIPConfig](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendipconfig) to create the configuration that assigns the public IP address that you also previously created to the application gateway. Use [New-AzureRmApplicationGatewayFrontendPort](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendport) to assign port 80 to be used to access the application gateway.
122+
123+
```azurepowershell-interactive
124+
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName myResourceGroupAG -Name myVNet
125+
$pip = Get-AzureRmPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
126+
$subnet=$vnet.Subnets[0]
127+
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration `
128+
-Name myAGIPConfig `
129+
-Subnet $subnet
130+
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig `
131+
-Name myAGFrontendIPConfig `
132+
-PublicIPAddress $pip
133+
$frontendport = New-AzureRmApplicationGatewayFrontendPort `
134+
-Name myFrontendPort `
135+
-Port 80
136+
```
137+
138+
### Create the backend pool
139+
140+
Use [New-AzureRmApplicationGatewayBackendAddressPool](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendaddresspool) to create the backend pool for the application gateway. Configure the settings for the backend pool using [New-AzureRmApplicationGatewayBackendHttpSettings](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendhttpsettings).
141+
142+
```azurepowershell-interactive
143+
$address1 = Get-AzureRmNetworkInterface -ResourceGroupName myResourceGroupAG -Name myNic1
144+
$address2 = Get-AzureRmNetworkInterface -ResourceGroupName myResourceGroupAG -Name myNic2
145+
$backendPool = New-AzureRmApplicationGatewayBackendAddressPool `
146+
-Name myAGBackendPool `
147+
-BackendIPAddresses $address1.ipconfigurations[0].privateipaddress, $address2.ipconfigurations[0].privateipaddress
148+
$poolSettings = New-AzureRmApplicationGatewayBackendHttpSettings `
149+
-Name myPoolSettings `
150+
-Port 80 `
151+
-Protocol Http `
152+
-CookieBasedAffinity Enabled `
153+
-RequestTimeout 120
154+
```
155+
156+
### Create the listener and add a rule
157+
158+
A listener is required to enable the application gateway to route traffic appropriately to the backend pool. Create a listener 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. Use [New-AzureRmApplicationGatewayRequestRoutingRule](/powershell/module/azurerm.network/new-azurermapplicationgatewayrequestroutingrule) to create a rule named *rule1*.
159+
160+
```azurepowershell-interactive
161+
$defaultlistener = New-AzureRmApplicationGatewayHttpListener `
162+
-Name myAGListener `
163+
-Protocol Http `
164+
-FrontendIPConfiguration $fipconfig `
165+
-FrontendPort $frontendport
166+
$frontendRule = New-AzureRmApplicationGatewayRequestRoutingRule `
167+
-Name rule1 `
168+
-RuleType Basic `
169+
-HttpListener $defaultlistener `
170+
-BackendAddressPool $backendPool `
171+
-BackendHttpSettings $poolSettings
172+
```
173+
174+
### Create the application gateway
175+
176+
Now that you created the necessary supporting resources, use [New-AzureRmApplicationGatewaySku](/powershell/module/azurerm.network/new-azurermapplicationgatewaysku) to specify parameters for the application gateway, and then use [New-AzureRmApplicationGateway](/powershell/module/azurerm.network/new-azurermapplicationgateway) to create it.
177+
178+
```azurepowershell-interactive
179+
$sku = New-AzureRmApplicationGatewaySku `
180+
-Name Standard_Medium `
181+
-Tier Standard `
182+
-Capacity 2
183+
New-AzureRmApplicationGateway `
184+
-Name myAppGateway `
185+
-ResourceGroupName myResourceGroupAG `
186+
-Location eastus `
187+
-BackendAddressPools $backendPool `
188+
-BackendHttpSettingsCollection $poolSettings `
189+
-FrontendIpConfigurations $fipconfig `
190+
-GatewayIpConfigurations $gipconfig `
191+
-FrontendPorts $frontendport `
192+
-HttpListeners $defaultlistener `
193+
-RequestRoutingRules $frontendRule `
194+
-Sku $sku
195+
```
196+
197+
## Test the application gateway
198+
199+
Installing IIS is not required to create the application gateway, but you installed it in this quickstart to verify whether the application gateway was successfully created. Use [Get-AzureRmPublicIPAddress](/powershell/module/azurerm.network/get-azurermpublicipaddress) 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.
200+
201+
```azurepowershell-interactive
202+
Get-AzureRmPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
203+
```
204+
205+
![Test application gateway](./media/quick-create-powershell/application-gateway-iistest.png)
206+
207+
When you refresh the browser, you should see the name of the other VM appear.
208+
209+
## Clean up resources
210+
211+
First explore the resources that were created with the application gateway, and then when no longer needed, you can use the [Remove-AzureRmResourceGroup](/powershell/module/azurerm.resources/remove-azurermresourcegroup) command to remove the resource group, application gateway, and all related resources.
212+
213+
```azurepowershell-interactive
214+
Remove-AzureRmResourceGroup -Name myResourceGroupAG
215+
```
216+
217+
## Next steps
218+
219+
> [!div class="nextstepaction"]
220+
> [Manage web traffic with an application gateway using Azure PowerShell](./tutorial-manage-web-traffic-powershell.md)
221+
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
---
2+
title: Create an application gateway that hosts multiple web sites - Azure PowerShell
3+
description: Learn how to create an application gateway that hosts multiple web sites using Azure Powershell.
4+
services: application-gateway
5+
author: vhorne
6+
7+
ms.service: application-gateway
8+
ms.topic: tutorial
9+
ms.workload: infrastructure-services
10+
ms.date: 3/22/2018
11+
ms.author: victorh
12+
ms.custom: mvc
13+
#Customer intent: As an IT administrator, I want to use Azure PowerShell to configure Application Gateway to host multiple web sites , so I can ensure my customers can acess the web information they need.
14+
---
15+
# Tutorial: Create an application gateway that hosts multiple web sites using Azure PowerShell
16+
17+
You can use Azure Powershell to [configure the hosting of multiple web sites](multiple-site-overview.md) when you create an [application gateway](overview.md). In this tutorial, 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 tutorial assumes that you own multiple domains and uses examples of *www.contoso.com* and *www.fabrikam.com*.
18+
19+
In this tutorial, you learn how to:
20+
21+
> [!div class="checklist"]
22+
> * Set up the network
23+
> * Create an application gateway
24+
> * Create backend listeners
25+
> * Create routing rules
26+
> * Create virtual machine scale sets with the backend pools
27+
> * Create a CNAME record in your domain
28+
29+
![Multi-site routing example](./media/tutorial-multiple-sites-powershell/scenario.png)
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 using [New-AzureRmVirtualNetworkSubnetConfig](/powershell/module/azurerm.network/new-azurermvirtualnetworksubnetconfig). Create the virtual network using [New-AzureRmVirtualNetwork](/powershell/module/azurerm.network/new-azurermvirtualnetwork) with the subnet configurations. And finally, create the public IP address 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+
54+
$agSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig `
55+
-Name myAGSubnet `
56+
-AddressPrefix 10.0.2.0/24
57+
58+
$vnet = New-AzureRmVirtualNetwork `
59+
-ResourceGroupName myResourceGroupAG `
60+
-Location eastus `
61+
-Name myVNet `
62+
-AddressPrefix 10.0.0.0/16 `
63+
-Subnet $backendSubnetConfig, $agSubnetConfig
64+
65+
$pip = New-AzureRmPublicIpAddress `
66+
-ResourceGroupName myResourceGroupAG `
67+
-Location eastus `
68+
-Name myAGPublicIPAddress `
69+
-AllocationMethod Dynamic
70+
```
71+
72+
## Create an application gateway
73+
74+
### Create the IP configurations and frontend port
75+
76+
Associate the subnet that you previously created to the application gateway using [New-AzureRmApplicationGatewayIPConfiguration](/powershell/module/azurerm.network/new-azurermapplicationgatewayipconfiguration). Assign the public IP address to the application gateway using [New-AzureRmApplicationGatewayFrontendIPConfig](/powershell/module/azurerm.network/new-azurermapplicationgatewayfrontendipconfig).
77+
78+
```azurepowershell-interactive
79+
$vnet = Get-AzureRmVirtualNetwork `
80+
-ResourceGroupName myResourceGroupAG `
81+
-Name myVNet
82+
83+
$subnet=$vnet.Subnets[0]
84+
85+
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration `
86+
-Name myAGIPConfig `
87+
-Subnet $subnet
88+
89+
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig `
90+
-Name myAGFrontendIPConfig `
91+
-PublicIPAddress $pip
92+
93+
$frontendport = New-AzureRmApplicationGatewayFrontendPort `
94+
-Name myFrontendPort `
95+
-Port 80
96+
```
97+
98+
### Create the backend pools and settings
99+
100+
Create the first backend address pool for the application gateway using [New-AzureRmApplicationGatewayBackendAddressPool](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendaddresspool). Configure the settings for the pool using [New-AzureRmApplicationGatewayBackendHttpSettings](/powershell/module/azurerm.network/new-azurermapplicationgatewaybackendhttpsettings).
101+
102+
```azurepowershell-interactive
103+
$contosoPool = New-AzureRmApplicationGatewayBackendAddressPool `
104+
-Name contosoPool
105+
106+
$fabrikamPool = New-AzureRmApplicationGatewayBackendAddressPool `
107+
-Name fabrikamPool
108+
109+
$poolSettings = New-AzureRmApplicationGatewayBackendHttpSettings `
110+
-Name myPoolSettings `
111+
-Port 80 `
112+
-Protocol Http `
113+
-CookieBasedAffinity Enabled `
114+
-RequestTimeout 120
115+
```
116+
117+
### Create the listeners and rules
118+
119+
Listeners are required to enable the application gateway to route traffic appropriately to the backend address pools. 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.fabrikam.com*.
120+
121+
Create the first listener 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 *contosoRule* using [New-AzureRmApplicationGatewayRequestRoutingRule](/powershell/module/azurerm.network/new-azurermapplicationgatewayrequestroutingrule).
122+
123+
```azurepowershell-interactive
124+
$contosolistener = New-AzureRmApplicationGatewayHttpListener `
125+
-Name contosoListener `
126+
-Protocol Http `
127+
-FrontendIPConfiguration $fipconfig `
128+
-FrontendPort $frontendport `
129+
-HostName "www.contoso.com"
130+
131+
$fabrikamlistener = New-AzureRmApplicationGatewayHttpListener `
132+
-Name fabrikamListener `
133+
-Protocol Http `
134+
-FrontendIPConfiguration $fipconfig `
135+
-FrontendPort $frontendport `
136+
-HostName "www.fabrikam.com"
137+
138+
$contosoRule = New-AzureRmApplicationGatewayRequestRoutingRule `
139+
-Name contosoRule `
140+
-RuleType Basic `
141+
-HttpListener $contosoListener `
142+
-BackendAddressPool $contosoPool `
143+
-BackendHttpSettings $poolSettings
144+
145+
$fabrikamRule = New-AzureRmApplicationGatewayRequestRoutingRule `
146+
-Name fabrikamRule `
147+
-RuleType Basic `
148+
-HttpListener $fabrikamListener `
149+
-BackendAddressPool $fabrikamPool `
150+
-BackendHttpSettings $poolSettings
151+
```
152+
153+
### Create the application gateway
154+
155+
Now that you created the necessary supporting resources, specify parameters for the application gateway using [New-AzureRmApplicationGatewaySku](/powershell/module/azurerm.network/new-azurermapplicationgatewaysku), and then create it using [New-AzureRmApplicationGateway](/powershell/module/azurerm.network/new-azurermapplicationgateway).
156+
157+
```azurepowershell-interactive
158+
$sku = New-AzureRmApplicationGatewaySku `
159+
-Name Standard_Medium `
160+
-Tier Standard `
161+
-Capacity 2
162+
163+
$appgw = New-AzureRmApplicationGateway `
164+
-Name myAppGateway `
165+
-ResourceGroupName myResourceGroupAG `
166+
-Location eastus `
167+
-BackendAddressPools $contosoPool, $fabrikamPool `
168+
-BackendHttpSettingsCollection $poolSettings `
169+
-FrontendIpConfigurations $fipconfig `
170+
-GatewayIpConfigurations $gipconfig `
171+
-FrontendPorts $frontendport `
172+
-HttpListeners $contosoListener, $fabrikamListener `
173+
-RequestRoutingRules $contosoRule, $fabrikamRule `
174+
-Sku $sku
175+
```
176+
177+
## Create virtual machine scale sets
178+
179+
In this example, you create two virtual machine scale sets that support the two backend pools that you created. The scale sets that you create are named *myvmss1* and *myvmss2*. 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.
180+
181+
```azurepowershell-interactive
182+
$vnet = Get-AzureRmVirtualNetwork `
183+
-ResourceGroupName myResourceGroupAG `
184+
-Name myVNet
185+
186+
$appgw = Get-AzureRmApplicationGateway `
187+
-ResourceGroupName myResourceGroupAG `
188+
-Name myAppGateway
189+
190+
$contosoPool = Get-AzureRmApplicationGatewayBackendAddressPool `
191+
-Name contosoPool `
192+
-ApplicationGateway $appgw
193+
194+
$fabrikamPool = Get-AzureRmApplicationGatewayBackendAddressPool `
195+
-Name fabrikamPool `
196+
-ApplicationGateway $appgw
197+
198+
for ($i=1; $i -le 2; $i++)
199+
{
200+
if ($i -eq 1)
201+
{
202+
$poolId = $contosoPool.Id
203+
}
204+
if ($i -eq 2)
205+
{
206+
$poolId = $fabrikamPool.Id
207+
}
208+
209+
$ipConfig = New-AzureRmVmssIpConfig `
210+
-Name myVmssIPConfig$i `
211+
-SubnetId $vnet.Subnets[1].Id `
212+
-ApplicationGatewayBackendAddressPoolsId $poolId
213+
214+
$vmssConfig = New-AzureRmVmssConfig `
215+
-Location eastus `
216+
-SkuCapacity 2 `
217+
-SkuName Standard_DS2 `
218+
-UpgradePolicyMode Automatic
219+
220+
Set-AzureRmVmssStorageProfile $vmssConfig `
221+
-ImageReferencePublisher MicrosoftWindowsServer `
222+
-ImageReferenceOffer WindowsServer `
223+
-ImageReferenceSku 2016-Datacenter `
224+
-ImageReferenceVersion latest
225+
226+
Set-AzureRmVmssOsProfile $vmssConfig `
227+
-AdminUsername azureuser `
228+
-AdminPassword "Azure123456!" `
229+
-ComputerNamePrefix myvmss$i
230+
231+
Add-AzureRmVmssNetworkInterfaceConfiguration `
232+
-VirtualMachineScaleSet $vmssConfig `
233+
-Name myVmssNetConfig$i `
234+
-Primary $true `
235+
-IPConfiguration $ipConfig
236+
237+
New-AzureRmVmss `
238+
-ResourceGroupName myResourceGroupAG `
239+
-Name myvmss$i `
240+
-VirtualMachineScaleSet $vmssConfig
241+
}
242+
```
243+
244+
### Install IIS
245+
246+
```azurepowershell-interactive
247+
$publicSettings = @{ "fileUris" = (,"https://raw.githubusercontent.com/davidmu1/samplescripts/master/appgatewayurl.ps1");
248+
"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }
249+
250+
for ($i=1; $i -le 2; $i++)
251+
{
252+
$vmss = Get-AzureRmVmss `
253+
-ResourceGroupName myResourceGroupAG `
254+
-VMScaleSetName myvmss$i
255+
256+
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss `
257+
-Name "customScript" `
258+
-Publisher "Microsoft.Compute" `
259+
-Type "CustomScriptExtension" `
260+
-TypeHandlerVersion 1.8 `
261+
-Setting $publicSettings
262+
263+
Update-AzureRmVmss `
264+
-ResourceGroupName myResourceGroupAG `
265+
-Name myvmss$i `
266+
-VirtualMachineScaleSet $vmss
267+
}
268+
```
269+
270+
## Create CNAME record in your domain
271+
272+
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.
273+
274+
```azurepowershell-interactive
275+
Get-AzureRmPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
276+
```
277+
278+
## Test the application gateway
279+
280+
Enter your domain name into the address bar of your browser. Such as, http://www.contoso.com.
281+
282+
![Test contoso site in application gateway](./media/tutorial-multiple-sites-powershell/application-gateway-iistest.png)
283+
284+
Change the address to your other domain and you should see something like the following example:
285+
286+
![Test fabrikam site in application gateway](./media/tutorial-multiple-sites-powershell/application-gateway-iistest2.png)
287+
288+
## Clean up resources
289+
290+
When no longer needed, remove the resource group, application gateway, and all related resources using [Remove-AzureRmResourceGroup](/powershell/module/azurerm.resources/remove-azurermresourcegroup).
291+
292+
```azurepowershell-interactive
293+
Remove-AzureRmResourceGroup -Name myResourceGroupAG
294+
```
295+
296+
## Next steps
297+
298+
In this tutorial, you learned how to:
299+
300+
> [!div class="checklist"]
301+
> * Set up the network
302+
> * Create an application gateway
303+
> * Create backend listeners
304+
> * Create routing rules
305+
> * Create virtual machine scale sets with the backend pools
306+
> * Create a CNAME record in your domain
307+
308+
> [!div class="nextstepaction"]
309+
> [Create an application gateway with URL path-based routing rules](./tutorial-url-route-powershell.md)

0 commit comments

Comments
 (0)
Please sign in to comment.