How is a reverse proxy different from a forward proxy?
A forward proxy works for clients: a browser is configured to send its requests through it, and websites see the proxy. A reverse proxy works for servers: visitors do not know it exists, they simply connect to app.example, and the proxy decides which internal service answers. The direction of trust is flipped. One protects or represents users, the other protects or represents applications. Proxy server covers the forward kind.
Why is a reverse proxy so useful on one machine with one address?
Our machines come with a single public IPv4, and there is only one port 443 on it. A reverse proxy lets many applications share that port: it reads the requested hostname from the TLS handshake (thanks to Server Name Indication (SNI)) and the Host header, then hands the request to the right local port. A shop on 127.0.0.1:3000, a dashboard on 127.0.0.1:8080 and a docs site served from disk can all live behind one address and one certificate manager.
What jobs does a reverse proxy usually take on?
- TLS termination: certificates and cipher settings in one place, plain HTTP on the loopback interface behind it.
- Routing: by hostname, path prefix or header, so
/apiand/can be different programs. - Load balancing: spreading requests across several backend processes or several machines, with health checks.
- Caching and compression: storing responses and compressing text so backends do less repeated work.
- Protection: request size limits, rate limits, timeouts and blocking of obviously bad paths before they reach application code.
- Hiding internals: backends never listen on the public interface, which shrinks what an attacker can reach.
What does a typical nginx reverse proxy look like?
upstream shop_nodes {
server 127.0.0.1:3001 max_fails=2 fail_timeout=10s;
server 127.0.0.1:3002 max_fails=2 fail_timeout=10s;
keepalive 32;
}
server {
listen 443 ssl;
http2 on;
server_name shop.example;
ssl_certificate /etc/letsencrypt/live/shop.example/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/shop.example/privkey.pem;
client_max_body_size 25m; # largest product photo upload
location / {
proxy_pass http://shop_nodes;
proxy_http_version 1.1;
proxy_set_header Connection ""; # reuse upstream keepalive
proxy_set_header Host $host; # keep the hostname the visitor typed
proxy_set_header X-Real-IP $remote_addr; # visitor address for app logs
proxy_set_header X-Forwarded-Proto $scheme; # tells the app the request was HTTPS
proxy_read_timeout 45s;
}
}
Test with nginx -t and reload with systemctl reload nginx. The http2 on line needs nginx 1.25.1 or later; on older packages put http2 on the listen line instead. Let's Encrypt with nginx shows how to get the certificate.
How do backends learn the real visitor address?
Behind a proxy every connection comes from 127.0.0.1, so applications read the forwarded headers instead. Configure the app or framework to trust those headers only from the proxy address, otherwise anyone can forge an X-Forwarded-For value and pose as another IP. In PHP-FPM setups the same concern applies to REMOTE_ADDR handling, and in nginx itself the real_ip module does the job when a CDN sits in front.
Which software can act as a reverse proxy?
nginx is the most common choice and also serves static files well. HAProxy is a specialist in balancing and health checks at both HTTP and TCP level. Caddy obtains certificates automatically with a very short config. Traefik reads routes from container labels, which suits Docker hosts; Docker hosts discusses that setup. Apache with mod_proxy works too if it is already part of your stack.
Which reverse proxy mistakes cause the most tickets?
Three mistakes account for most support questions. Timeouts that are shorter than a slow export or upload cause 504 errors that look like application bugs, so raise proxy_read_timeout only on the paths that need it. WebSocket routes need the Upgrade and Connection headers passed through, or real-time features silently fall back to polling. Redirect loops appear when the app thinks it is on plain HTTP and keeps sending visitors to HTTPS; passing X-Forwarded-Proto and telling the framework to trust it fixes that. Reading the proxy error log with tail -n 40 /var/log/nginx/error.log usually names the culprit within a line or two.
How big should the proxy machine be?
On a single box the proxy shares the machine with the apps and uses a small fraction of it. A standalone balancer in front of several backends mostly needs network capacity and a few fast cores for TLS: the S2 with 2x 10 Gbps ports handles a large amount of HTTPS, and the S13 adds 2x 25 Gbps links for heavy traffic. Remember that responses served to visitors count as outgoing traffic whether they come from cache or a backend.
Machines for a Reverse Proxy or Balancer
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| S1 | Intel Xeon E-2276G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $53.32 | $53.32 (1 month) |
| S2 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $58.39 | $58.39 (1 month) |
| S4 | Intel Xeon E-2388G | 8 / 16 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $87.52 | $87.52 (1 month) |
| S13 | AMD EPYC 4345P | 8 / 16 | 128 GB DDR5 | 2x 2 TB NVMe | 2x 25 Gbps | $237.92 | $237.92 (1 month) |
Keep Reading
Proxy server
A server that sits between clients and destinations and forwards their traffic, in forward or reverse form, for control, caching or privacy.
OpenServer Name Indication (SNI)
The TLS extension that lets one IP address serve HTTPS for many domains, how it works in nginx, and how to test and troubleshoot it.
Opennginx reverse proxy in Docker
Run nginx in a container as the front door for other containers, route by host name, pass real client IPs and add TLS.
OpenLet's Encrypt with nginx
Get free TLS certificates for nginx with certbot, choose the nginx or webroot method, and confirm automatic renewal works.
OpenFAQ
Quick Answers
A load balancer is one job a reverse proxy can do. A reverse proxy may also terminate TLS, route by hostname, cache and filter requests.
Yes. A reverse proxy reads the hostname from SNI and the Host header and sends each site to its own backend on the same machine.
It sees the proxy connection. Read X-Real-IP or X-Forwarded-For, trusting those headers only when they come from the proxy.
nginx is a good all-rounder that also serves files. HAProxy has richer balancing and health checks. Both handle typical sites easily.
It reduces exposure by keeping backends off the public interface and adds limits and timeouts, but the applications still need their own fixes.