Reverse Proxies and API Gateways
On this page
What Proxies Commonly Break
- Header forwarding (Host, X-Forwarded-For, X-Request-Id)
- Body size limits (413), buffering, and timeouts (504)
- Protocol mismatch (HTTP/1.1 vs HTTP/2), WebSocket upgrades
Essential Debug Headers
curl -sv https://example.com/api -H 'x-request-id: dbg-001' --max-time 5 || true
Safe Reload Pattern
- Validate config before reload.
- Reload, don't restart, to keep connections where possible.
# nginx nginx -t nginx -s reload # haproxy (example) haproxy -c -f /etc/haproxy/haproxy.cfg
Timeout Alignment
- Client timeout > proxy timeout > upstream timeout.
- Set per-route budgets (uploads, long polls).
Failure Modes
- Buffer bloat: large responses buffered, memory spikes; tune buffering.
- Header explosion: too many cookies/headers → 431/400; enforce limits.
- Misrouted traffic: wrong Host/SNI → wrong backend.
Checklist
# Compare direct backend vs proxy path curl -sv http://<BACKEND_IP>:8080/api --max-time 5 || true curl -sv https://example.com/api --max-time 5 || true