Reverse Proxy
What is a reverse proxy?
A reverse proxy is a server placed between users and one or more backend servers. Visitors send their requests to the proxy, which forwards each one to the appropriate server and returns the response as if it came from a single origin. The client never talks directly to the application servers, which stay hidden behind it.
How a reverse proxy works
The flow has four steps: the browser resolves the domain through DNS to the proxy's address, the proxy receives the request, it picks a backend based on rules (path, host, headers, load), and it relays the response back, sometimes after modifying it. A minimal Nginx configuration looks like this:
server { listen 443 ssl; server_name example.com; location /api/ { proxy_pass http://127.0.0.1:3000; } }
Here, every request to /api/ is passed to an application listening on port 3000, while the rest of the site can be served from elsewhere.
What a reverse proxy is used for
- Load balancing: spreading traffic across several servers to avoid overload (see load balancing).
- TLS termination: handling HTTPS and the SSL certificate in one place instead of on every server.
- Caching and compression: serving frequent responses without hitting the backend.
- Security: hiding internal servers, filtering malicious requests and applying rate limiting.
- Routing: exposing several services, for example microservices, under one domain.
Reverse proxy vs forward proxy vs CDN
| Aspect | Reverse proxy | Forward proxy | CDN |
|---|---|---|---|
| Acts on behalf of | The servers | The clients | The servers, at the edge |
| Typical position | In front of the backend | In front of users or a company network | Distributed across many locations |
| Main goal | Routing, security, performance | Anonymity, filtering, access control | Fast delivery close to the user |
| Examples | Nginx, HAProxy, Traefik | Corporate web gateway | Cloudflare, Fastly |
A CDN is in practice a network of reverse proxies spread around the world, which is why the two notions overlap.
Best practices and pitfalls
- Forward the original client IP with headers such as
X-Forwarded-For, otherwise the backend only sees the proxy. - Set sensible timeouts and health checks so a failing server is removed from rotation.
- Keep security HTTP headers consistent at the proxy level.
- Avoid making the proxy a single point of failure: run at least two instances for critical apps.
Reverse proxy and SEO
A reverse proxy can serve a blog or an app under a subfolder of the main domain instead of a subdomain, which keeps authority consolidated on one host. It must preserve canonical URLs, status codes and headers, or search engines may index the wrong address.
Reverse proxy at BeBranded
On our web app projects, we put a reverse proxy or an edge layer in front of the application to handle HTTPS, caching and routing, so the product stays fast and secure as traffic grows. Discover our web apps service.