Reverse Proxy & TLS Termination
How a reverse proxy terminates TLS with ACME/Let's Encrypt, routes traffic, sets forwarding headers, and compares Nginx, Caddy, and managed edges.
TL;DR
A reverse proxy sits in front of your app servers to handle TLS termination (via ACME / Let's Encrypt), virtual-host routing, compression, and forwarding headers (Host, X-Forwarded-For, X-Forwarded-Proto). Pick Caddy for zero-config HTTPS on a single server, Nginx for high-throughput tuning, or a managed edge (Cloudflare) when you don't want to run a proxy VM at all.
Intent
Understand what a reverse proxy does at the edge of your backend, how ACME automates TLS certificates, and when to choose Nginx, Caddy, or a managed edge.
Problem
Application runtimes (Node.js, Go, Python) are built to run business logic, not to juggle TLS certificates, HTTP/2/HTTP/3 upgrades, gzip/Brotli compression, or host-based routing across multiple services on port 443. Exposing app ports directly forces every service to manage certificates and leaves them open to slow-client attacks.
Solution
Place a reverse proxy on ports 80/443 while keeping upstream apps bound to 127.0.0.1 or a private network:
- TLS termination & ACME: The proxy proves domain ownership to a Certificate Authority (like Let's Encrypt) via ACME (
HTTP-01challenge on port80orDNS-01TXT record), obtains a short-lived certificate, and renews it automatically before expiry. - Routing & headers: The proxy inspects
Hostand path, forwards requests to the right upstream (127.0.0.1:3000), and passesHost,X-Forwarded-For, andX-Forwarded-Protoso the app knows the original client IP and scheme. - Compression & buffering: The proxy compresses responses (
gzip/zstd) and buffers slow clients so upstream worker threads aren't tied up waiting on mobile networks.
| Option | Strengths | Trade-offs |
|---|---|---|
| Caddy | Automatic ACME HTTPS, HTTP/3, tiny Caddyfile | Smaller third-party module ecosystem than Nginx |
| Nginx | Battle-tested performance, rich directive control | Manual Certbot/ACME setup and reload plumbing |
| Managed edge (Cloudflare) | Anycast DDoS protection, auto certs, zero VM upkeep | Vendor coupling; traffic passes through third-party edge |
Real-world analogy
▶ Flow: watch it work
Client → TLS Reverse Proxy → Upstream App
Press Start or tap any step dot to trace the path.
▸All steps (4)
Code
Compare a minimal Caddyfile (automatic HTTPS included) with a minimal Nginx server block (paired with Certbot certificates):
# /etc/caddy/Caddyfile (not run)
app.example.com {
encode zstd gzip
reverse_proxy 127.0.0.1:3000
}When you DON'T need this
- Static sites on a managed edge (like this site): Cloudflare Workers/Pages or Vercel already terminate TLS, issue certificates, and compress assets—running Nginx in front would add a redundant hop and a VM to patch.
- Internal cluster-only services: If a service is only called by other Pods inside a private VPC or service mesh, you don't need a public-facing Nginx/Caddy instance on every node.
- Cost / complexity trade-off: Running your own Caddy/Nginx on a VM is cheap ($5–$10/mo), but you own OS patching, firewall rules (
80/443open,3000blocked externally), and certificate renewal alerts. A managed load balancer or edge eliminates VM maintenance in exchange for per-hour or per-request pricing.
When to use / when to avoid
- You are hosting one or more backend apps on a VM or Docker Compose host and need HTTPS on port 443.
- You want centralized rate limiting, security headers, and compression in front of multiple services.
- Your app is already deployed on a managed edge platform that handles TLS and routing.
- You bind your upstream app to 0.0.0.0:3000 without a firewall, letting clients bypass the proxy.
How to implement
Bind the upstream app to loopback or a private network
Listen on 127.0.0.1:3000 (or an internal Docker network) so callers cannot bypass the proxy.
Configure ACME TLS and forwarding headers
Point DNS A/AAAA records to the proxy, open ports 80 and 443, and forward Host, X-Forwarded-For, and X-Forwarded-Proto.
Test renewal and headers
Verify curl -I https://app.example.com shows a valid certificate and that your app reads X-Forwarded-Proto safely only from trusted proxy IPs.
Pros / Cons
- Single TLS and security-header boundary in front of any language or framework.
- ACME automates certificate issuance and renewal without manual CSRs.
- Buffers slow clients and serves static/compressed responses efficiently.
- Self-hosted proxies add a single point of failure unless paired with DNS/LB failover.
- Misconfigured X-Forwarded-For trust lets clients spoof their IP address.
Relations
Check yourself
Check Yourself
1. Why should your upstream app bind to 127.0.0.1:3000 (or an internal network) when sitting behind Nginx or Caddy?
2. What happens if an Nginx reverse proxy omits proxy_set_header X-Forwarded-Proto $scheme;?
Sources
Related Notes
Linux Processes, Signals, and Exit Codes
How PID 1, SIGTERM, graceful shutdown, SIGKILL, exit codes 137 and 143, exec in entrypoints, and tini/--init keep container shutdowns clean.
Backups & Disaster Recovery
Design reliable backups using RPO/RTO targets, the 3-2-1 rule, logical vs physical PostgreSQL backups, regular restore drills, and pragmatic DR tiers.