A reverse proxy is a server placed in front of one or more web servers that receives client requests and forwards them to those servers, so clients connect to the proxy instead of the origin. It is commonly used for load balancing, caching, TLS termination, and security. Every other proxy type in this glossary are forward proxies, which act for the client. A reverse proxy acts for the server.
Reverse proxies are deployed by the operator of the web service itself, not by whoever is making requests to it. Nginx, Varnish, and Apache HTTP Server can run as reverse proxies, and Cloudflare's CDN acts as one.
How a Reverse Proxy Works
- A client sends an ordinary request to the site's address. The reverse proxy appears to the client like a normal web server, so no client configuration is needed.
- The proxy decides which backend server should handle the request and forwards it. The HTTP standard (RFC 9110) calls this a gateway: it acts as the origin server for the client but forwards requests inbound to other servers.
- The backend responds, and the proxy returns the content as if it were the origin. Nginx, for example, buffers the full backend response by default before sending it on.
Reverse Proxy vs. Forward Proxy
| Forward proxy | Reverse proxy | |
|---|---|---|
| Acts for | The client | The server |
| Set up by | The user or client app | The site's operator |
| Client configuration | Required | None |
| Hides | The client's identity from servers | The servers' identities from clients |
| Typical uses | Privacy, web scraping, internet access from behind a firewall | Load balancing, caching, TLS termination, access to servers behind a firewall |
What Reverse Proxies Do
- Load balancing: spread requests across several backend servers. Nginx uses round-robin by default and also offers least-connections and IP hash, which keeps each client on the same server.
- Failover: Nginx marks a server as failed after errors and avoids it for a set time.
- Caching: store copies of responses, such as static content, to take load off slower backend servers.
- TLS termination: decrypt client requests and encrypt responses, so backend servers don't have to.
- Compression: compress content to speed up load times.
- One address for many servers: bring several servers into the same URL space.
Reverse Proxy vs. Load Balancer
Load balancing is one job a reverse proxy can do, not a separate kind of server. Nginx acts as an HTTP load balancer by passing requests to a group of upstream servers. A reverse proxy that forwards to a single backend, such as Apache sending one URL path to one internal host, is still a reverse proxy without balancing anything.
What It Means for Web Scraping
- You reach the proxy first: when a site uses a reverse proxy, your request is handled there before the origin sees it, so caching, rate limits and bot checks can be applied at the proxy.
- Client IP in headers: the backend sees the reverse proxy's address, so the proxy often passes the client's IP in a header. Nginx's docs show
X-Real-IP, and X-Forwarded-For is the de facto standard header for this. If you connect through a forward proxy, that header carries the forward proxy's IP, not yours.
Security Considerations
- Decrypted traffic: a reverse proxy that terminates TLS holds the site's certificate key and handles requests unencrypted.
- Open proxy risk: Apache's docs warn that open proxy servers are dangerous to your network and the internet at large. A reverse proxy doesn't need forward proxying (
ProxyRequests) turned on.