Skip to Content
Mengty Learns
Foundations

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.

explanationbeginnerTested with nginx 1.30.8 (docs), caddy 2.11.9 (docs)Updated Nov 26, 2026

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

TL;DR

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:

  1. TLS termination & ACME: The proxy proves domain ownership to a Certificate Authority (like Let's Encrypt) via ACME (HTTP-01 challenge on port 80 or DNS-01 TXT record), obtains a short-lived certificate, and renews it automatically before expiry.
  2. Routing & headers: The proxy inspects Host and path, forwards requests to the right upstream (127.0.0.1:3000), and passes Host, X-Forwarded-For, and X-Forwarded-Proto so the app knows the original client IP and scheme.
  3. Compression & buffering: The proxy compresses responses (gzip/zstd) and buffers slow clients so upstream worker threads aren't tied up waiting on mobile networks.
OptionStrengthsTrade-offs
CaddyAutomatic ACME HTTPS, HTTP/3, tiny CaddyfileSmaller third-party module ecosystem than Nginx
NginxBattle-tested performance, rich directive controlManual Certbot/ACME setup and reload plumbing
Managed edge (Cloudflare)Anycast DDoS protection, auto certs, zero VM upkeepVendor coupling; traffic passes through third-party edge

Real-world analogy

▶ Flow: watch it work

Client → TLS Reverse Proxy → Upstream App

Overview of Client → TLS Reverse Proxy → Upstream App. 4 steps.
Overview4 steps in this flow

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/443 open, 3000 blocked 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

When to use
  • 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.
When to avoid
  • 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

Pros
  • 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.
Cons
  • 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