Application Gateway: Layer 7
Configure Azure Application Gateway for HTTP-aware load balancing β listeners, routing rules, path-based routing, TLS termination, and autoscaling.
Application Gateway: Layer 7
Application Gateway is Azureβs regional HTTP/HTTPS load balancer. Unlike Azure Load Balancer (Layer 4), Application Gateway understands HTTP β it can route based on URLs, host headers, and cookies.
π¬ Video coming soon
Application Gateway Components and Routing
Application Gateway Components and Routing
~13:00Application Gateway is a smart bouncer at a nightclub β it reads your ticket (URL) and sends you to the right room. Unlike Load Balancer (routes by IP/port), Application Gateway understands HTTP. It can route /api/* to one backend and /images/* to another, handles TLS certificates, and includes WAF.
Component Flow
Traffic flows through Application Gateway in this order:
Client
β
Frontend IP (public or private)
β
Listener (port + protocol + hostname)
β
Routing Rule (basic or path-based)
β
HTTP Settings (backend port, protocol, affinity, timeout)
β
Backend Pool (VMs, VMSS, App Service, IPs)
β
Health Probe (checks backend health)
Component details:
| Component | Purpose | Options |
|---|---|---|
| Frontend IP | IP that clients connect to | Public IP, private IP, or both |
| Listener | Listens on a port/protocol for incoming requests | Basic: single site on a port. Multi-site: multiple hostnames on the same port (Host header routing). |
| Routing rule | Maps listener to backend | Basic: all traffic to one backend pool. Path-based: different URL paths to different pools (e.g., /images/* to pool A, /api/* to pool B). |
| HTTP settings | Defines how AG talks to the backend | Backend port, protocol (HTTP/HTTPS), cookie affinity, connection draining, request timeout, hostname override |
| Backend pool | Target servers | VMs, VMSS, App Services, IP addresses, FQDNs |
| Health probe | Checks backend health | Custom path, interval, unhealthy threshold, match conditions |
Multi-Site Listeners
A single Application Gateway can host multiple websites using multi-site listeners:
| Listener | Hostname | Backend Pool |
|---|---|---|
| Listener 1 | app.pinnacle.com | Pool-App |
| Listener 2 | api.pinnacle.com | Pool-API |
| Listener 3 | portal.pinnacle.com | Pool-Portal |
All three share the same frontend IP and port (443). The listener matches the Host header to route to the correct backend.
Path-Based Routing
Path-based routing sends different URL paths to different backend pools:
| Path Rule | URL Pattern | Backend Pool |
|---|---|---|
| Rule 1 | /images/* | Pool-Static (storage-optimised VMs) |
| Rule 2 | /api/* | Pool-API (compute-optimised VMs) |
| Default | /* (everything else) | Pool-Web (general web servers) |
π’ Raviβs scenario: Pinnacle Financialβs web application serves static images, an API, and web pages. Path-based routing lets Ravi optimise each backend pool independently β more CPU for the API, more storage for images.
Scaling
| Mode | How It Works | Best For |
|---|---|---|
| Manual | You set a fixed instance count (1-125) | Predictable traffic, cost control |
| Autoscale | Set minimum and maximum instance count; AG scales based on traffic | Variable traffic, spiky workloads |
Autoscale is recommended for production. You set min=2 (for HA) and max=125. Application Gateway scales within these bounds based on concurrent connections, throughput, and compute utilisation.
TLS Configuration
TLS termination (TLS offload):
- Client connects to AG over HTTPS (port 443)
- AG decrypts the traffic (using your certificate)
- AG forwards to backend over HTTP (port 80)
- Reduces backend CPU load; AG handles certificate management
End-to-end TLS:
- Client connects to AG over HTTPS
- AG decrypts, inspects (for routing and WAF), then re-encrypts
- AG connects to backend over HTTPS
- Backend must have its own certificate
- Required when compliance mandates encryption in transit at every hop
Certificate management:
- Upload PFX certificates to Application Gateway directly
- Or reference certificates stored in Azure Key Vault (recommended β centralised, auto-renewal)
Rewrite Rules
Rewrite rule sets modify HTTP headers and URL paths on requests and responses:
Common uses:
- Remove server headers (security: donβt expose backend server type)
- Add security headers (HSTS, X-Content-Type-Options)
- Redirect HTTP to HTTPS
- Modify request URLs before forwarding to backend
- Add/remove/modify cookies
Configuration:
- Create a rewrite rule set
- Add conditions (match on headers, URL, query string)
- Add actions (set, delete, or append headers; rewrite URL)
- Associate with routing rules
Rewrite rules are processed in order. You can have multiple rule sets associated with different routing rules.
When to Use Application Gateway vs Load Balancer
| Feature | Application Gateway | Azure Load Balancer |
|---|---|---|
| OSI layer | Layer 7 (HTTP/HTTPS) | Layer 4 (TCP/UDP) |
| URL path routing | Yes β route /api/* and /images/* to different backends | No β routes by IP and port only |
| Host header routing | Yes β multi-site listeners for multiple domains | No |
| TLS termination | Yes β offloads TLS and supports end-to-end TLS | No β passes through encrypted traffic |
| WAF integration | Yes β built-in WAF v2 SKU available | No |
| Cookie affinity | Yes β cookie-based session affinity | Source IP affinity only (tuple hash) |
| Non-HTTP traffic | No β HTTP and HTTPS only | Yes β any TCP or UDP protocol |
| Scope | Regional only | Regional (cross-region available with global tier) |
Rule of thumb: If your application uses HTTP/HTTPS and needs URL routing, TLS termination, or WAF β use Application Gateway. For non-HTTP protocols (databases, custom TCP services) β use Load Balancer.
Key Takeaways
- Application Gateway is a Layer 7 (HTTP/HTTPS) regional load balancer
- Multi-site listeners route based on Host header; path-based rules route by URL
- TLS termination offloads encryption; end-to-end TLS re-encrypts to backend
- Autoscale (min 2, max 125) is recommended for production
- Use AG for HTTP workloads; LB for non-HTTP or pure Layer 4
Test Your Knowledge
Ravi's web application has three components: /api/*, /static/*, and general pages. Each needs different backend servers. Which Application Gateway feature should he use?
Aisha's compliance team requires encryption at every hop, including between Application Gateway and backend servers. What TLS mode should she configure?
Next up: Azure Front Door: Global Delivery β Global HTTP load balancing with CDN, WAF, and Private Link origins.