A reverse proxy is a server that sits in front of one or more web servers and receives requests on their behalf. It forwards each request to the right backend and returns the response, often handling HTTPS, caching, compression and load balancing along the way. Nginx, Caddy, HAProxy and Cloudflare are common examples.
How it works
Forward vs reverse
A forward proxy acts for clients (your browser goes through it to reach many sites). A reverse proxy acts for servers (many visitors go through it to reach one site). Visitors usually don't know it's there.
What reverse proxies do
- TLS termination: one place for certificates; backends speak plain HTTP on a private network.
- Routing:
/apito one service, everything else to another. - Load balancing and health checks across backends.
- Caching and compression.
- Security: hiding backend IPs, rate limiting, a web application firewall.
Errors you'll see
Because the proxy talks to the backend, backend problems surface as proxy errors: 502 Bad Gateway (backend unreachable or sent garbage), 504 Gateway Timeout (backend too slow), and Cloudflare's 52x codes.
Examples
A minimal nginx reverse proxy for an app on port 3000:
server {
listen 443 ssl;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
On a Mac
For local development, Caddy (caddy reverse-proxy --from localhost:8443 --to localhost:3000) gives a dev app HTTPS in one command. curl -sI against a site often reveals the proxy in a server or via header.
See it in the app
On a dev machine, LightAtom's Ports view shows the proxy's listening port, and the connections view its connections to each backend.
Frequently asked questions
What is a reverse proxy used for?
Handling HTTPS, routing requests, load balancing, caching and protecting backend servers, all at a single entry point.
What is the difference between a proxy and a reverse proxy?
A forward proxy represents clients going out to many servers. A reverse proxy represents servers receiving traffic from many clients.
Is a load balancer a reverse proxy?
Layer 7 load balancers are reverse proxies. Layer 4 load balancers forward connections without parsing HTTP.
Is Cloudflare a reverse proxy?
Yes. When proxying is on, visitors connect to Cloudflare, which forwards requests to your origin server.