On this page
Reverse Proxy and Load Balancing
Reverse proxy is more than just "forwarding requests"—TLS termination, caching, compression, rate limiting, health checks, and blue-green deployments all converge on traffic management at this layer. The configuration philosophies of nginx, Caddy, and HAProxy differ significantly.
Overview
A reverse proxy acts as a server-side facade—it receives all external requests, handles TLS termination, SNI routing, rate limiting, and logging, then forwards requests to backend services. A load balancer distributes requests across multiple backend instances according to strategies (round-robin, least connections, IP hash), thereby improving availability and throughput. Caddy is known for automatic TLS (ACME + Let's Encrypt with zero configuration), while nginx and HAProxy dominate enterprise environments with high performance and rich L4/L7 features. Understanding reverse proxies is a prerequisite for deploying any internet-facing service.
Reverse Proxy vs. Forward Proxy
Caddy Configuration
grafana.liz6.com {
reverse_proxy 127.0.0.1:3000 {
header_up Host {upstream_hostport}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
chat.liz6.com {
reverse_proxy 127.0.0.1:3001
}
Responsibilities of a reverse proxy:
- TLS Termination: Caddy handles TLS → backend HTTP → backend doesn't need to handle TLS
- SNI Routing: Route to different backends on the same port (443) based on SNI
- Request Rewriting: Add X-Forwarded-* headers, modify path/headers
- Rate Limiting: Per-client or per-endpoint rate limiting
- Access Logging: Centralized logging (Caddy JSON access log)
L4 vs. L7 Load Balancing
Load Balancing Algorithms
Round Robin: Round-robin across backends
Least Connections: Select backend with fewest connections (L7 only)
Random: Random selection
IP Hash: Same client IP → same backend → sticky
Consistent Hash: Hash ring → only 1/N remap when backends change
Weighted: Backend weight → weight=3 gets 3x traffic
Health Check:
passive: Detect failures from actual request errors (max_fails=N)
active: Periodic GET /health → expect 200 → mark as down on failure
slow_start: Gradually increase traffic after backend recovery (avoid flood)
References
- Caddy: caddyserver.com/docs/caddyfile/directives/reverse_proxy
- nginx: nginx.org/en/docs/http/ngx_http_upstream_module.html
- HAProxy: haproxy.org
Keywords: reverse proxy, SNI routing, L4/L7 LB, health check, sticky session, rate limiting, Caddy