AZ-500 LAB 26 ~2 giờ Chương 06 Secure Networking

Application Gateway v2 — Publish Web App

Triển khai Azure Application Gateway v2 (Standard_v2 SKU) để publish web app nội bộ, cấu hình backend pool, HTTP listener, routing rule và health probe — foundation cho WAF ở Lab 27.

Application Gateway v1 đã retire ngày 28/04/2026. Lab này và production chỉ dùng Standard_v2 hoặc WAF_v2 SKU. Không dùng Standard hoặc WAF (v1).
Cảnh báo chi phí: Application Gateway v2 ~$0.246/giờ (fixed) + $0.008/CU. Ước tính lab 2h ~$0.60. Xóa ngay sau lab. Standard_v2 là SKU tối thiểu hiện tại.

🎯 Mục Tiêu Lab

Tạo VNet với subnet riêng cho AppGW và subnet backend

Deploy Application Gateway v2 (Standard_v2 SKU) với Public IP Standard

Tạo VM backend chạy Nginx (hoặc dùng App Service)

Cấu hình Backend Pool, HTTP Settings, Listener, Routing Rule

Kiểm tra Health Probe và truy cập web qua AppGW public IP

Chuẩn bị sẵn sàng cho WAF Policy (Lab 27)

📋 Chuẩn Bị

Yêu cầu:
  • Azure subscription Contributor role
  • Azure CLI đã cài và đăng nhập
  • Region: southeastasia
Kiến thức cần có:
  • HTTP/HTTPS load balancing concept
  • Backend pool, listener, routing rule
  • Health probe cơ bản

🏗️ Kịch Bản

Web app chạy trên VM backend trong subnet private. Không expose VM trực tiếp ra Internet. Application Gateway v2 đứng giữa, nhận HTTP từ Internet và forward vào backend — Layer 7 load balancing với health check tự động.

Internet
    │ HTTP :80
    ▼
[App Gateway v2] Public IP (Standard)
    │  snet-appgw: 10.0.1.0/24
    │  Listener: port 80
    │  Routing Rule → Backend Pool
    ▼
[Backend VM] Nginx :80
    │  snet-backend: 10.0.2.0/24
    │  Private IP only
    └─ Health Probe: GET / → HTTP 200

🧪 Các Bước Thực Hiện

1

Tạo VNet, Subnet và Backend VM

Application Gateway cần subnet riêng (không share với VM). Backend VM cài Nginx để test.

Cách 1 — Portal
  1. 1.1Tạo RG: rg-lab26-appgw → Region: Southeast Asia
  2. 1.2VNet: vnet-lab26 → 10.0.0.0/16 → Subnet snet-appgw 10.0.1.0/24 (cho AppGW)
  3. 1.3Subnet snet-backend 10.0.2.0/24 (cho backend VMs)
  4. 1.4Tạo VM Ubuntu → snet-backend → Public IP: None → NSG: cho phép port 80 inbound từ VNet
Azure CLI— VNet + backend VM + Nginx
RG="rg-lab26-appgw"
LOCATION="southeastasia"

az group create --name $RG --location $LOCATION

# Tạo VNet với 2 subnet
az network vnet create \
  --resource-group $RG --name vnet-lab26 \
  --address-prefix 10.0.0.0/16 \
  --subnet-name snet-appgw --subnet-prefix 10.0.1.0/24

az network vnet subnet create \
  --resource-group $RG --vnet-name vnet-lab26 \
  --name snet-backend --address-prefix 10.0.2.0/24

# Tạo backend VM chạy Nginx, không có public IP
az vm create \
  --resource-group $RG \
  --name vm-backend-lab26 \
  --image Ubuntu2204 \
  --vnet-name vnet-lab26 \
  --subnet snet-backend \
  --public-ip-address "" \
  --admin-username azureuser \
  --generate-ssh-keys \
  --size Standard_B1s \
  --custom-data '#!/bin/bash
apt-get update -y
apt-get install -y nginx
echo "

Backend VM - Lab 26 AZ-500

Served via Application Gateway

" > /var/www/html/index.html systemctl enable nginx systemctl start nginx' # Mở port 80 cho AppGW trong NSG az vm open-port \ --resource-group $RG \ --name vm-backend-lab26 \ --port 80 # Lấy private IP backend VM BACKEND_IP=$(az vm show \ --resource-group $RG \ --name vm-backend-lab26 \ --show-details --query privateIps --output tsv) echo "Backend VM Private IP: $BACKEND_IP"
2

Tạo Public IP và Application Gateway v2

Application Gateway v2 cần Public IP Standard SKU. Deploy mất ~5–10 phút.

Cách 1 — Portal
  1. 2.1Application gateways → + Create → RG: rg-lab26-appgw → Name: appgw-lab26
  2. 2.2Tier: Standard V2 → Enable autoscaling: Yes → Min instances: 0, Max: 2 → Zone: None (lab)
  3. 2.3VNet: vnet-lab26 → Subnet: snet-appgw → Public IP → New → Name: pip-appgw-lab26 → SKU: Standard
  4. 2.4Tab Backends → + Add a backend pool → Name: bp-nginx → Target type: IP → IP: BACKEND_VM_IP
  5. 2.5Tab Configuration → + Add routing rule → Rule name: rule-http → Listener: port 80 → Backend: bp-nginx → Review + Create
Azure CLI— Application Gateway Standard_v2
RG="rg-lab26-appgw"

# Lấy backend IP
BACKEND_IP=$(az vm show \
  --resource-group $RG --name vm-backend-lab26 \
  --show-details --query privateIps --output tsv)

# Tạo Public IP Standard cho AppGW
az network public-ip create \
  --resource-group $RG \
  --name pip-appgw-lab26 \
  --sku Standard \
  --allocation-method Static

# Tạo Application Gateway Standard_v2 với tất cả thành phần
# (mất ~5-10 phút)
az network application-gateway create \
  --resource-group $RG \
  --name appgw-lab26 \
  --location southeastasia \
  --sku Standard_v2 \
  --capacity 1 \
  --vnet-name vnet-lab26 \
  --subnet snet-appgw \
  --public-ip-address pip-appgw-lab26 \
  --frontend-port 80 \
  --http-settings-port 80 \
  --http-settings-protocol Http \
  --routing-rule-type Basic \
  --servers "$BACKEND_IP" \
  --priority 1

echo "Application Gateway deploy started. Waiting ~10 minutes..."

# Kiểm tra trạng thái
az network application-gateway show \
  --resource-group $RG \
  --name appgw-lab26 \
  --query "provisioningState" --output tsv
3

Kiểm Tra Health Probe và Kết Nối

Sau khi deploy xong, kiểm tra backend health và truy cập web qua AppGW public IP.

Azure CLI— kiểm tra backend health
RG="rg-lab26-appgw"

# Lấy Public IP của AppGW
APPGW_IP=$(az network public-ip show \
  --resource-group $RG --name pip-appgw-lab26 \
  --query ipAddress --output tsv)

echo "AppGW Public IP: $APPGW_IP"
echo "Test: curl http://$APPGW_IP"

# Test kết nối qua curl
curl -s http://$APPGW_IP

# Kiểm tra backend health state
az network application-gateway show-backend-health \
  --resource-group $RG \
  --name appgw-lab26 \
  --query "backendAddressPools[0].backendHttpSettingsCollection[0].servers[0].health" \
  --output tsv

# Xem toàn bộ cấu hình AppGW
az network application-gateway show \
  --resource-group $RG \
  --name appgw-lab26 \
  --query "{sku:sku.name,tier:sku.tier,state:provisioningState}" \
  --output table
Kết quả mong đợi: Backend health = Healthy. curl http://APPGW_IP trả về HTML: "Backend VM - Lab 26 AZ-500". Truy cập browser http://APPGW_IP thấy trang web.
4

Cấu Hình Custom Health Probe và HTTP Settings

Custom health probe kiểm tra endpoint cụ thể thay vì root path. Connection draining giúp graceful shutdown.

Cách 1 — Portal
  1. 4.1appgw-lab26 → Health probes → + Add → Name: probe-nginx → Protocol: HTTP → Host: 10.0.2.x (backend IP)
  2. 4.2Path: / → Interval: 30s → Timeout: 30s → Unhealthy threshold: 3 → Save
  3. 4.3HTTP Settings → appgw-lab26BackendHttpSettings → gắn probe-nginx → Connection draining: Enable, 60s → Save
Azure CLI— custom health probe
RG="rg-lab26-appgw"

BACKEND_IP=$(az vm show \
  --resource-group $RG --name vm-backend-lab26 \
  --show-details --query privateIps --output tsv)

# Thêm custom health probe
az network application-gateway probe create \
  --resource-group $RG \
  --gateway-name appgw-lab26 \
  --name probe-nginx \
  --protocol Http \
  --host "$BACKEND_IP" \
  --path "/" \
  --interval 30 \
  --timeout 30 \
  --threshold 3

# Cập nhật HTTP settings gắn probe
az network application-gateway http-settings update \
  --resource-group $RG \
  --gateway-name appgw-lab26 \
  --name appGatewayBackendHttpSettings \
  --probe probe-nginx \
  --connection-draining-timeout 60

# Kiểm tra lại backend health sau khi gắn probe
az network application-gateway show-backend-health \
  --resource-group $RG \
  --name appgw-lab26 \
  --output table

📊 Kết Quả Đầu Ra Lab 26

AppGW Standard_v2 deployed

provisioningState: Succeeded, SKU: Standard_v2

Backend health: Healthy

Health probe GET / → HTTP 200 từ Nginx backend

Web app accessible qua AppGW IP

curl http://APPGW_IP → "Backend VM - Lab 26 AZ-500"

Sẵn sàng cho WAF (Lab 27)

AppGW Standard_v2 có thể upgrade lên WAF_v2 để gắn WAF Policy

🧹 Dọn Dẹp Tài Nguyên

Lưu ý: Nếu tiếp tục Lab 27, giữ lại rg-lab26-appgw. Chỉ xóa khi hoàn thành Lab 27.

Azure CLI
# Chỉ xóa sau khi hoàn thành Lab 27
az group delete --name rg-lab26-appgw --yes --no-wait

❓ Câu Hỏi Ôn Tập

1. Application Gateway v2 khác gì v1? Tại sao v1 bị retire và không được dùng nữa?

Gợi ý: v2 có autoscaling, zone redundancy, static VIP, header rewrite, custom error pages. v1 retire 28/04/2026 — Microsoft yêu cầu migrate sang v2.

2. Subnet của Application Gateway cần có kích thước tối thiểu là bao nhiêu? Tại sao?

Gợi ý: Tối thiểu /24 (256 địa chỉ) cho v2. AppGW dùng nhiều IP private khi autoscale — Microsoft khuyến nghị /24 cho production.

3. Health Probe hoạt động như thế nào? Nếu backend không pass health check thì điều gì xảy ra?

Gợi ý: AppGW định kỳ gửi HTTP request tới backend. Nếu fail (timeout hoặc non-2xx) vượt threshold → backend bị đánh dấu Unhealthy → không nhận traffic mới.

4. Sự khác nhau giữa Standard_v2 và WAF_v2 SKU của Application Gateway?

Gợi ý: WAF_v2 = Standard_v2 + Web Application Firewall. Có thể nâng cấp từ Standard_v2 lên WAF_v2 mà không cần redeploy. Lab 27 sẽ thực hiện điều này.

Lab 25: Firewall Policy Thư viện Labs Lab 27: WAF Policy