Skip to content

Commit e9ff442

Browse files
committed
Created tutorial, updated TOC.
1 parent b2d12f9 commit e9ff442

File tree

3 files changed

+338
-1
lines changed

3 files changed

+338
-1
lines changed

articles/frontdoor/standard-premium/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
href: ../front-door-quickstart-template-samples.md?toc=%2fazure%2ffrontdoor%2fstandard-premium%2ftoc.json
2222
- name: Tutorials
2323
items:
24+
- name: Add delivery rules with the Azure CLI
25+
href: front-door-add-rules-cli.md
2426
- name: Configure security headers with Rules engine
2527
href: ../front-door-security-headers.md?toc=%2fazure%2ffrontdoor%2fstandard-premium%2ftoc.json
2628
- name: Concepts

articles/frontdoor/standard-premium/create-front-door-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.topic: sample
55
author: duau
66
ms.author: duau
77
ms.service: frontdoor
8-
ms.date: 12/15/2021
8+
ms.date: 12/30/2021
99
ms.custom: devx-track-azurecli
1010

1111
---
Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
---
2+
title: Add delivery rules to Azure Front Door with the Azure CLI
3+
description: Learn how to create an Azure Front Door Standard/Premium (Preview) with the Azure CLI. Then, add delivery rules to enhance control over your web app behavior.
4+
ms.topic: sample
5+
author: duau
6+
ms.author: duau
7+
ms.service: frontdoor
8+
ms.date: 12/30/2021
9+
ms.custom: devx-track-azurecli
10+
11+
---
12+
13+
# Tutorial: Add and customize delivery rules for Azure Front Door Standard/Premium (Preview) with Azure CLI
14+
15+
Azure Front Door Standard/Premium (Preview) is a fast, reliable, and secure modern cloud CDN that uses the Microsoft global edge network and integrates with intelligent threat protection. Azure Front Door Standard focuses on content delivery. Azure Front Door Premium adds extensive security capabilities and customization. This tutorial focuses on creating an Azure Front Door profile, then adding delivery rules for more granular control over your web apps.
16+
17+
> [!NOTE]
18+
> This documentation is for Azure Front Door Standard/Premium (Preview). Looking for information on Azure Front Door? View [Azure Front Door Docs](../front-door-overview.md).
19+
20+
In this tutorial, you'll learn how to:
21+
22+
> [!div class="checklist"]
23+
> - Create an Azure Front Door profile.
24+
> - Create two instances of a web app.
25+
> - Create a new security policy.
26+
> - Verify connectivity to your web apps.
27+
> - Create a rule set.
28+
> - Create a rule and add it to the rule set.
29+
> - Add actions or conditions to your rules.
30+
31+
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
32+
33+
[!INCLUDE [azure-cli-prepare-your-environment](../../../includes/azure-cli-prepare-your-environment.md)]
34+
35+
## Create an Azure Front Door
36+
37+
### Create a resource group
38+
39+
For this quickstart, you'll need two resource groups. One in *Central US* and the second in *East US*.
40+
41+
Run [az group create](/cli/azure/group#az_group_create) to create resource groups.
42+
43+
```azurecli
44+
az group create \
45+
--name myRGFDCentral \
46+
--location centralus
47+
48+
az group create \
49+
--name myRGFDEast \
50+
--location eastus
51+
```
52+
53+
### Create an Azure Front Door profile
54+
55+
Run [az afd profile create](/cli/azure/afd/profile#az_afd_profile_create) to create an Azure Front Door profile.
56+
57+
```azurecli
58+
az afd profile create \
59+
--profile-name contosoafd \
60+
--resource-group myRGFDCentral \
61+
--sku Premium_AzureFrontDoor \
62+
--subscription mysubscription
63+
```
64+
65+
### Create two instances of a web app
66+
67+
You need two instances of a web application that run in different Azure regions for this tutorial. Both the web application instances run in Active/Active mode, so either one can service traffic.
68+
69+
If you don't already have a web app, use the following script to set up two example web apps.
70+
71+
#### Create app service plans
72+
73+
Before you can create the web apps you'll need two app service plans, one in *Central US* and the second in *East US*.
74+
75+
Run [az appservice plan create](/cli/azure/appservice/plan#az_appservice_plan_create&preserve-view=true) to create your app service plans.
76+
77+
```azurecli
78+
az appservice plan create \
79+
--name myAppServicePlanCentralUS \
80+
--resource-group myRGFDCentral
81+
82+
az appservice plan create \
83+
--name myAppServicePlanEastUS \
84+
--resource-group myRGFDEast
85+
```
86+
87+
#### Create web apps
88+
89+
Run [az webapp create](/cli/azure/webapp#az_webapp_create&preserve-view=true) to create a web app in each of the app service plans in the previous step. Web app names have to be globally unique.
90+
91+
Run [az webapp list-runtimes](/cli/azure/webapp#az_webapp_create&preserve-view=true) to see a list of built-in stacks for web apps.
92+
93+
```azurecli
94+
az webapp create \
95+
--name WebAppContoso-001 \
96+
--resource-group myRGFDCentral \
97+
--plan myAppServicePlanCentralUS \
98+
--runtime "DOTNETCORE|2.1"
99+
100+
az webapp create \
101+
--name WebAppContoso-002 \
102+
--resource-group myRGFDEast \
103+
--plan myAppServicePlanEastUS \
104+
--runtime "DOTNETCORE|2.1"
105+
```
106+
107+
Make note of the default host name of each web app so you can define the backend addresses when you deploy the Front Door in the next step.
108+
109+
### Add an endpoint
110+
111+
Run [az afd endpoint create](/cli/azure/afd/endpoint#az_afd_endpoint_create) to create an endpoint in your profile. You can create multiple endpoints in your profile after finishing the create experience.
112+
113+
```azurecli
114+
az afd endpoint create \
115+
--resource-group myRGFDCentral \
116+
--endpoint-name contoso-frontend \
117+
--profile-name contosoafd \
118+
--origin-response-timeout-seconds 60 \
119+
--enabled-state Enabled
120+
```
121+
122+
### Create an origin group
123+
124+
Run [az afd origin-group create](/cli/azure/afd/origin-group#az_afd_origin_group_create) to create an origin group that contains your two web apps.
125+
126+
```azurecli
127+
az afd origin-group create \
128+
--resource-group myRGFDCentral \
129+
--origin-group-name og1 \
130+
--profile-name contosoafd \
131+
--probe-request-type GET \
132+
--probe-protocol Http \
133+
--probe-interval-in-seconds 120 \
134+
--probe-path /test1/azure.txt \
135+
--sample-size 4 \
136+
--successful-samples-required 3 \
137+
--additional-latency-in-milliseconds 50
138+
```
139+
140+
#### Add origins to the group
141+
142+
Run [az afd origin create](/cli/azure/afd/origin#az_afd_origin_create) to add an origin to your origin group.
143+
144+
```azurecli
145+
az afd origin create \
146+
--resource-group myRGFDCentral \
147+
--host-name webappcontoso-1.azurewebsites.net
148+
--profile-name contosoafd \
149+
--origin-group-name og1 \
150+
--origin-name contoso1 \
151+
--origin-host-header webappcontoso-1.azurewebsites.net \
152+
--priority 1 \
153+
--weight 1000 \
154+
--enabled-state Enabled \
155+
--http-port 80 \
156+
--https-port 443
157+
```
158+
159+
Repeat this step and add your second origin.
160+
161+
```azurecli
162+
az afd origin create \
163+
--resource-group myRGFDCentral \
164+
--host-name webappcontoso-2.azurewebsites.net
165+
--profile-name contosoafd \
166+
--origin-group-name og1 \
167+
--origin-name contoso2 \
168+
--origin-host-header webappcontoso-2.azurewebsites.net \
169+
--priority 1 \
170+
--weight 1000 \
171+
--enabled-state Enabled \
172+
--http-port 80 \
173+
--https-port 443
174+
```
175+
176+
### Add a route
177+
178+
Run [az afd route create](/cli/azure/afd/route#az_afd_route_create) to map your frontend endpoint to the origin group. This route forwards requests from the endpoint to *og1*.
179+
180+
```azurecli
181+
az afd route create \
182+
--resource-group myRGFDCentral \
183+
--endpoint-name contoso-frontend \
184+
--profile-name contosoafd \
185+
--route-name route1 \
186+
--https-redirect Enabled \
187+
--origin-group og1 \
188+
--supported-protocols Https \
189+
--link-to-default-domain Enabled \
190+
--forwarding-protocol MatchRequest
191+
```
192+
193+
## Create a new security policy
194+
195+
### Create a WAF policy
196+
197+
Run [az network front-door waf-policy create](/cli/azure/network/front-door/waf-policy#az_network_front_door_waf_policy_create) to create a WAF policy for one of your resource groups.
198+
199+
Create a new WAF policy for your Front Door. This example creates a policy that's enabled and in prevention mode.
200+
201+
```azurecli
202+
az network front-door waf-policy create
203+
--name contosoWAF /
204+
--resource-group myRGFDCentral /
205+
--sku Premium_AzureFrontDoor
206+
--disabled false /
207+
--mode Prevention
208+
```
209+
210+
> [!NOTE]
211+
> If you select `Detection` mode, your WAF doesn't block any requests.
212+
213+
### Create the security policy
214+
215+
Run [az afd security-policy create](/cli/azure/afd/security-policy#az_afd_security_policy_create) to apply your WAF policy to the endpoint's default domain.
216+
217+
```azurecli
218+
az afd security-policy create \
219+
--resource-group myRGFDCentral \
220+
--profile-name contosoafd \
221+
--security-policy-name contososecurity \
222+
--domains /subscriptions/mysubscription/resourcegroups/myRGFDCentral/providers/Microsoft.Cdn/profiles/contosoafd/afdEndpoints/contoso-frontend.z01.azurefd.net \
223+
--waf-policy /subscriptions/mysubscription/resourcegroups/myRGFDCentral/providers/Microsoft.Network/frontdoorwebapplicationfirewallpolicies/contosoWAF
224+
```
225+
226+
## Verify Azure Front Door
227+
228+
When you create the Azure Front Door Standard/Premium profile, it takes a few minutes for the configuration to be deployed globally. Once completed, you can access the frontend host you created. In a browser, go to `contoso-frontend.z01.azurefd.net`. Your request will automatically get routed to the nearest server from the specified servers in the origin group.
229+
230+
To test instant global failover, we'll use the following steps:
231+
232+
1. Open a browser, as described above, and go to the frontend address: `contoso-frontend.azurefd.net`.
233+
234+
2. In the Azure portal, search for and select *App services*. Scroll down to find one of your web apps, **WebAppContoso-1** in this example.
235+
236+
3. Select your web app, and then select **Stop**, and **Yes** to verify.
237+
238+
4. Refresh your browser. You should see the same information page.
239+
240+
>[!TIP]
241+
>There is a little bit of delay for these actions. You might need to refresh again.
242+
243+
5. Find the other web app, and stop it as well.
244+
245+
6. Refresh your browser. This time, you should see an error message.
246+
247+
:::image type="content" source="../media/create-front-door-portal/web-app-stopped-message.png" alt-text="Both instances of the web app stopped":::
248+
249+
## Create a secret
250+
251+
Secrets are used to reference your own certificate stored in Azure Key Vault. You must specify the secret name when creating a custom domain if you want to use your own certificate for TLS encryption.
252+
253+
Run [az afd secret create](/cli/azure/afd/secret#az_afd_secret_create) to create a new secret in your Azure Front Door profile.
254+
255+
```azurecli
256+
az afd secret create \
257+
--profile-name contosoafd \
258+
--resource-group myRGFDCentral \
259+
--secret-name contosocert \
260+
--secret-source /subscriptions/mysubscription/resourceGroups/myRGFDCentral/providers/Microsoft.KeyVault/vaults/contosokeyvault/certificates/contosocert \
261+
--use-latest-version true
262+
```
263+
264+
## Create a rule set
265+
266+
By adding a rule set, you can customize how HTTP requests are handled at the edge and provide more controls over your web application behaviors. Run [az afd rule-set create](/cli/azure/afd/rule-set#az_afd_rule_set_create) to create a rule set in your Azure Front Door profile.
267+
268+
```azurecli
269+
az afd rule-set create \
270+
--profile-name contosoafd \
271+
--resource-group myRGFDCentral \
272+
--rule-set-name contosorules
273+
```
274+
275+
## Create a delivery rule and add it to your rule set
276+
277+
Create a new delivery rule within your new rule set. Run [az afd rule create](/cli/azure/afd/rule#az_afd_rule_create) to create a delivery rule in your rule set. For this example, we'll create a rule for an http to https redirect.
278+
279+
```azurecli
280+
az afd rule create \
281+
--resource-group myRGFDCentral \
282+
--rule-set-name contosorules \
283+
--profile-name contosoafd \
284+
--order 1 \
285+
--match-variable RequestScheme \
286+
--operator Equal \
287+
--match-values HTTP \
288+
--rule-name "redirect" \
289+
--action-name "UrlRedirect" \
290+
--redirect-protocol Https \
291+
--redirect-type Moved
292+
```
293+
294+
## Add an action or condition to your delivery rule
295+
296+
You might find that you need to further customize your new delivery rule. You can add actions or conditions as needed after creation. Run [az afd rule action add](/cli/azure/afd/rule/action#az_afd_rule_action_add) or [az afd rule condition add](/cli/azure/afd/rule/condition#az_afd_rule_condition_add) to update your rule.
297+
298+
### Add an action
299+
300+
```azurecli
301+
az afd rule action add \
302+
--resource-group myRGFDCentral \
303+
--rule-set-name contosorules \
304+
--profile-name contosoafd \
305+
--rule-name redirect \
306+
--action-name "CacheExpiration" \
307+
--cache-behavior BypassCache
308+
```
309+
310+
### Add a condition
311+
312+
```azurecli
313+
az afd rule condition add \
314+
--resource-group myRGFDCentral \
315+
--rule-set-name contosorules \
316+
--profile-name contosoafd \
317+
--rule-name redirect \
318+
--match-variable RemoteAddress \
319+
--operator GeoMatch \
320+
--match-values "TH"
321+
```
322+
323+
## Clean up resources
324+
325+
When you don't need the resources for the Front Door, delete both resource groups. Deleting the resource groups also deletes the Front Door and all its related resources.
326+
327+
Run [az group delete](/cli/azure/group#az_group_delete&preserve-view=true):
328+
329+
```azurecli
330+
az group delete \
331+
--name myRGFDCentral
332+
333+
az group delete \
334+
--name myRGFDEast
335+
```

0 commit comments

Comments
 (0)