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 1174f60

Browse files
committedFeb 5, 2018
new multisite tutorial
1 parent 4f8dca8 commit 1174f60

33 files changed

+601
-311
lines changed
 

‎articles/application-gateway/TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
## Configure multiple site hosting
4141
### [Azure portal](application-gateway-create-multisite-portal.md)
4242
### [Azure PowerShell](application-gateway-create-multisite-azureresourcemanager-powershell.md)
43+
### [Azure CLI](tutorial-multisite-cli.md)
4344
## Configure external redirection
4445
### [Azure PowerShell](tutorial-external-site-redirect-powershell.md)
4546
### [Azure CLI](tutorial-external-site-redirect-cli.md)

‎articles/application-gateway/application-gateway-create-multisite-azureresourcemanager-powershell.md

Lines changed: 228 additions & 232 deletions
Large diffs are not rendered by default.

‎articles/application-gateway/application-gateway-create-multisite-portal.md

Lines changed: 126 additions & 79 deletions
Large diffs are not rendered by default.
Loading
Loading
Loading
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
---
2+
title: Create an application gateway with multiple site hosting - Azure CLI | Microsoft Docs
3+
description: Learn how to create an application gateway that hosts multiple sites 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/26/2018
15+
ms.author: davidmu
16+
17+
---
18+
# Create an application gateway with multiple site hosting using the Azure CLI
19+
20+
You can use the Azure CLI to configure [hosting of multiple web sites](application-gateway-multi-site-overview.md) when you create an [application gateway](application-gateway-introduction.md). In this tutorial, you create backend 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*.
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+
> * Create listeners and routing rules
28+
> * Create virtual machine scale sets with the backend pools
29+
> * Create a CNAME record in your domain
30+
31+
![Multi-site routing example](./media/tutorial-multisite-cli/scenario.png)
32+
33+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
34+
35+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
36+
37+
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).
38+
39+
## Create a resource group
40+
41+
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).
42+
43+
The following example creates a resource group named *myResourceGroupAG* in the *eastus* location.
44+
45+
```azurecli-interactive
46+
az group create --name myResourceGroupAG --location eastus
47+
```
48+
49+
## Create network resources
50+
51+
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 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).
52+
53+
```azurecli-interactive
54+
az network vnet create \
55+
--name myVNet \
56+
--resource-group myResourceGroupAG \
57+
--location eastus \
58+
--address-prefix 10.0.0.0/16 \
59+
--subnet-name myAGSubnet \
60+
--subnet-prefix 10.0.1.0/24
61+
az network vnet subnet create \
62+
--name myBackendSubnet \
63+
--resource-group myResourceGroupAG \
64+
--vnet-name myVNet \
65+
--address-prefix 10.0.2.0/24
66+
az network public-ip create \
67+
--resource-group myResourceGroupAG \
68+
--name myAGPublicIPAddress
69+
```
70+
71+
## Create the application gateway
72+
73+
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.
74+
75+
```azurecli-interactive
76+
az network application-gateway create \
77+
--name myAppGateway \
78+
--location eastus \
79+
--resource-group myResourceGroupAG \
80+
--vnet-name myVNet \
81+
--subnet myAGsubnet \
82+
--capacity 2 \
83+
--sku Standard_Medium \
84+
--http-settings-cookie-based-affinity Disabled \
85+
--frontend-port 80 \
86+
--http-settings-port 80 \
87+
--http-settings-protocol Http \
88+
--public-ip-address myAGPublicIPAddress
89+
```
90+
91+
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:
92+
93+
- *appGatewayBackendPool* - An application gateway must have at least one backend address pool.
94+
- *appGatewayBackendHttpSettings* - Specifies that port 80 and an HTTP protocol is used for communication.
95+
- *appGatewayHttpListener* - The default listener associated with *appGatewayBackendPool*.
96+
- *appGatewayFrontendIP* - Assigns *myAGPublicIPAddress* to *appGatewayHttpListener*.
97+
- *rule1* - The default routing rule that is associated with *appGatewayHttpListener*.
98+
99+
### Add the backend pools
100+
101+
Add the backend pools named *contosoPool* and *fabrikamPool* that are needed to contain the backend servers using [az network application-gateway address-pool create](/cli/azure/application-gateway#az_network_application_gateway_address_pool_create).
102+
103+
```azurecli-interactive
104+
az network application-gateway address-pool create \
105+
--gateway-name myAppGateway \
106+
--resource-group myResourceGroupAG \
107+
--name contosoPool
108+
az network application-gateway address-pool create \
109+
--gateway-name myAppGateway \
110+
--resource-group myResourceGroupAG \
111+
--name fabrikamPool
112+
```
113+
114+
### Add listeners
115+
116+
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.fabrikam.com*.
117+
118+
Add the listeners named *contosoListener* and *fabrikamListener* 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).
119+
120+
```azurecli-interactive
121+
az network application-gateway http-listener create \
122+
--name contosoListener \
123+
--frontend-ip appGatewayFrontendIP \
124+
--frontend-port appGatewayFrontendPort \
125+
--resource-group myResourceGroupAG \
126+
--gateway-name myAppGateway \
127+
--host-name www.contoso.com
128+
az network application-gateway http-listener create \
129+
--name fabrikamListener \
130+
--frontend-ip appGatewayFrontendIP \
131+
--frontend-port appGatewayFrontendPort \
132+
--resource-group myResourceGroupAG \
133+
--gateway-name myAppGateway \
134+
--host-name www.fabrikam.com
135+
```
136+
137+
### Add routing rules
138+
139+
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. For example, if you have a rule using a basic listener and a rule using a multi-site listener both on the same port, the rule with the multi-site listener must be listed before the rule with the basic listener in order for the multi-site rule to function as expected.
140+
141+
In this example, you create two new rules and delete the default rule that was created when you created the application gateway. You can add the rule using [az network application-gateway rule create](/cli/azure/application-gateway#az_network_application_gateway_rule_create).
142+
143+
```azurecli-interactive
144+
az network application-gateway rule create \
145+
--gateway-name myAppGateway \
146+
--name contosoRule \
147+
--resource-group myResourceGroupAG \
148+
--http-listener contosoListener \
149+
--rule-type Basic \
150+
--address-pool contosoPool
151+
az network application-gateway rule create \
152+
--gateway-name myAppGateway \
153+
--name fabrikamRule \
154+
--resource-group myResourceGroupAG \
155+
--http-listener fabrikamListener \
156+
--rule-type Basic \
157+
--address-pool fabrikamPool
158+
az network application-gateway rule delete \
159+
--gateway-name myAppGateway \
160+
--name rule1 \
161+
--resource-group myResourceGroupAG
162+
```
163+
164+
## Create virtual machine scale sets
165+
166+
In this example, you create three virtual machine scale sets that support the three backend pools in the application gateway. The scale sets that you create are named *myvmss1*, *myvmss2*, and *myvmss3*. Each scale set contains two virtual machine instances on which you install NGINX.
167+
168+
```azurecli-interactive
169+
for i in `seq 1 2`; do
170+
if [ $i -eq 1 ]
171+
then
172+
poolName="contosoPool"
173+
fi
174+
if [ $i -eq 2 ]
175+
then
176+
poolName="fabrikamPool"
177+
fi
178+
az vmss create \
179+
--name myvmss$i \
180+
--resource-group myResourceGroupAG \
181+
--image UbuntuLTS \
182+
--admin-username azureuser \
183+
--admin-password Azure123456! \
184+
--instance-count 2 \
185+
--vnet-name myVNet \
186+
--subnet myBackendSubnet \
187+
--vm-sku Standard_DS2 \
188+
--upgrade-policy-mode Automatic \
189+
--app-gateway myAppGateway \
190+
--backend-pool-name $poolName
191+
done
192+
```
193+
194+
### Install NGINX
195+
196+
```azurecli-interactive
197+
for i in `seq 1 2`; do
198+
az vmss extension set \
199+
--publisher Microsoft.Azure.Extensions \
200+
--version 2.0 \
201+
--name CustomScript \
202+
--resource-group myResourceGroupAG \
203+
--vmss-name myvmss$i \
204+
--settings '{
205+
"fileUris": ["https://raw.githubusercontent.com/davidmu1/samplescripts/master/install_nginx.sh"],
206+
"commandToExecute": "./install_nginx.sh" }'
207+
done
208+
```
209+
210+
## Create a CNAME record in your domain
211+
212+
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.
213+
214+
```azurecli-interactive
215+
az network public-ip show \
216+
--resource-group myResourceGroupAG \
217+
--name myAGPublicIPAddress \
218+
--query [dnsSettings.fqdn] \
219+
--output tsv
220+
```
221+
222+
The use of A-records is not recommended because the VIP may change when the application gateway is restarted.
223+
224+
## Test the application gateway
225+
226+
Enter your domain name into the address bar of your browser. Such as, http://www.contoso.com.
227+
228+
![Test contoso site in application gateway](./media/tutorial-multisite-cli/application-gateway-nginxtest1.png)
229+
230+
Change the address to your other domain and you should see something like the following example:
231+
232+
![Test fabrikam site in application gateway](./media/tutorial-multisite-cli/application-gateway-nginxtest2.png)
233+
234+
## Next steps
235+
236+
In this tutorial, you learned how to:
237+
238+
> [!div class="checklist"]
239+
> * Set up the network
240+
> * Create an application gateway
241+
> * Create listeners and routing rules
242+
> * Create virtual machine scale sets with the backend pools
243+
> * Create a CNAME record in your domain
244+
245+
> [!div class="nextstepaction"]
246+
> [Learn more about what you can do with application gateway](application-gateway-introduction.md)

0 commit comments

Comments
 (0)
Please sign in to comment.