Azure · Application Gateway · West USVM + App Gateway field guide
Clear the routeto port 80
Put an Ubuntu VM running Nginx behind an Azure Application Gateway: one VNet, two subnets, an NSG, a cloud-init script and a Basic-tier gateway. Nine moves, each with the Portal clicks and the exact az commands.
Everything this build creates, with its name, address or setting, and the move that creates it. The names follow the lab's xfusion- prefix; the script builder lets you pick your own.
Departures · West US
--:--
Move
Resource
Name
Details
The network
Two subnets. → One way in.
The gateway gets a subnet of its own and is the only public path for web traffic. The VM sits in the other subnet behind the NSG. Hover or tap any part of the map.
The nine moves
Lay the track → in order
Each move depends on the one before: the gateway needs the VM's private IP, the VM needs the NSG and subnet, and the subnet needs the VNet. Every move shows the Portal route and the CLI.
1
Move 1 · Prerequisites
Sign in and get an SSH key
Log in to Azure and make sure a key pair exists. The VM uses SSH key authentication, so the Portal wizard needs your public key pasted in as text.
Keep secrets out of scripts. Sign in with az login --use-device-code instead of writing a username and password into the script, even as a comment.
# Log in if not already authenticated
az login --use-device-code
az account show --output table
# Generate an SSH key pair if one doesn't existSSH_KEY_PATH="$HOME/.ssh/id_rsa"
if [ ! -f "$SSH_KEY_PATH.pub" ]; then
ssh-keygen -t rsa -b 4096 -f "$SSH_KEY_PATH" -N ""
fi
cat "$SSH_KEY_PATH.pub"
Sign in at portal.azure.com with the lab credentials from showcreds on the azure-client host.
Open a terminal on the azure-client host and keep it open. You'll paste the key printed by cat into the VM wizard in move 5.
2
Move 2 · Network
Create the VNet and two subnets
The Application Gateway needs a subnet of its own, separate from the VM's.
if az vm show -g "$RESOURCE_GROUP" -n "$VM_NAME" >/dev/null 2>&1; then
az vm delete -g "$RESOURCE_GROUP" -n "$VM_NAME" --yes --no-wait
while az vm show -g "$RESOURCE_GROUP" -n "$VM_NAME" >/dev/null 2>&1; do
sleep 10
done
fi
az disk list -g "$RESOURCE_GROUP" \
--query "[?starts_with(name, '$VM_NAME')].name" -o tsv | \
xargs -r -I{} az disk delete -g "$RESOURCE_GROUP" -n {} --yes
Create a resource → Virtual machine → Create.
Basics: name xfusion-vm, West US, an Ubuntu image (e.g. Ubuntu Server 22.04 LTS), size Standard_B1s, SSH public key → Use existing public key → paste ~/.ssh/id_rsa.pub.
Disks: OS disk type Standard HDD.
Networking: VNet xfusion-vnet, subnet xfusion-vm-subnet. NIC security group → Advanced → choose xfusion-nsg.
Advanced: paste the cloud-init text from move 4 into Custom data.
Review + create → Create.
6
Move 6 · Address
Read the VM's private IP
The gateway's backend pool targets this address directly. Traffic from the gateway to the VM stays inside the VNet.
VM_PRIVATE_IP=$(az vm show \
--resource-group "$RESOURCE_GROUP" --name "$VM_NAME" \
--show-details --query privateIps --output tsv)
echo "VM private IP: $VM_PRIVATE_IP"
Open xfusion-vm → Overview → note the Private IP address.
7
Move 7 · Front door
Create the gateway's public IP
Standard SKU, static. The gateway needs a Standard public IP. In the Portal you can also create it inline in move 8.
AGW_PIP_NAME="xfusion-agw-ip"
az network public-ip create \
--resource-group "$RESOURCE_GROUP" --name "$AGW_PIP_NAME" \
--sku Standard --allocation-method Static \
--location "$LOCATION"
Optional: Create a resource → Public IP address → name xfusion-agw-ip, SKU Standard, assignment Static, West US. Or skip it and create it in the gateway wizard.
8
Move 8 · The gateway
Create the Application Gateway (Basic)
Listener on HTTP :80 → routing rule → HTTP settings on :80 → backend pool with the VM's private IP.
Why az rest? The CLI's --sku check doesn't accept the Basic tier yet. The script sends the ARM request body straight to the REST API instead, which skips that client-side check.
Check this body against your script. The request body in the source guide is cut off, so the one shown here is rebuilt from the Application Gateway ARM schema (API 2023-11-01).
Open xfusion-agw → Overview → wait for Provisioning state: Succeeded.
Note the Frontend public IP address.
Browse to http://<AGW_PUBLIC_IP>. You should see the Nginx welcome page.
The first request
200 or 502? → Try it.
A gateway that's up doesn't mean the site is. If Nginx isn't answering yet, the gateway's health probe marks the VM unhealthy and returns 502 Bad Gateway. This is a simulation you can run.
Set the VM's state, then send the request.
cloud-init has finished: Nginx is enabled and listening on port 80.
Public IPListenerRulePoolNginx
$ curl -sS -m 10 -o /dev/null -w "HTTP status: %{http_code}\n" "http://$AGW_PUBLIC_IP"
Press "Send request" to run the simulation.
Your script
Name the route. → Get the script.
Pick a prefix, region and address space. You get one bash script covering all nine moves, with every resource named consistently.
setup-agw-vm.shbash
Route set
Sign-off
Eight signals → to green
Tap each signal as you confirm it in Azure. All eight green means traffic runs end to end.