Networking and the web
What is a Reverse Proxy?
Definition
A reverse proxy is a server that sits in front of one or more backend servers and receives client requests on their behalf, so clients only ever talk to it.
Reverse Proxy in more detail
The client believes the reverse proxy is the website. Behind it there might be one application server or fifty, written in different languages and listening on private ports; the proxy decides which one gets each request based on hostname, path, headers or health. Nginx, Caddy, HAProxy, Envoy and Traefik are the usual choices, and every managed load balancer and CDN is one too.
Concentrating traffic at a single front door is what makes the pattern useful. TLS certificates live there rather than in every application, so the backends can speak plain HTTP on a private network. Compression, request buffering, static file serving, response caching, header rewriting, IP allow-lists, rate limiting and access logging all happen once, in a component built for it, instead of being reimplemented in each service.
It is also the seam that makes deployments and migrations survivable. You can route /api to a new service while everything else keeps hitting the old one, shift a percentage of traffic to a canary, or hold requests briefly while an instance restarts. The cost is that the proxy is now on the critical path for everything, so it needs redundancy of its own, and backends must read the client IP from X-Forwarded-For — which they should trust only from the proxy itself.
Reverse Proxy example
# nginx: one public entry point, several private backends
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location /api/ {
proxy_pass http://127.0.0.1:8080; # the API service
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
proxy_pass http://127.0.0.1:3000; # the web app
}
}Reverse Proxy — common questions
- Is a reverse proxy the same as a load balancer?
- Overlapping, not identical. A load balancer's job is distributing traffic across instances; a reverse proxy's job is fronting backends, which may include load balancing plus TLS termination, caching, routing and rewriting. Most modern products do both.
- Why put a reverse proxy in front of a Node or Python app?
- To handle the things an application server is not specialised for: TLS, slow clients, compression, static assets, connection limits and graceful restarts. It also lets you run several instances of the app behind one address.
- How does the backend see the real client IP?
- Through headers the proxy adds, usually X-Forwarded-For and X-Forwarded-Proto, or the standard Forwarded header. Applications must only trust these when the request came from a known proxy, since a client can otherwise forge them.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary