A reverse proxy is a server that stands in front of your web servers and receives every request meant for them. Visitors connect to it as if it were the website itself. It decides which backend should answer, forwards the request, and returns the response. The visitor never talks to your application servers directly, and usually never knows they exist. Most busy websites run behind one, often several layers deep.
What sits where
visitor -> reverse proxy (example.com, port 443) -> app server (127.0.0.1:3000)
Compare that with a forward proxy, which sits next to the client. Your script connects to the forward proxy, and the proxy goes out to any website on the internet. Same basic mechanism, opposite side of the connection. A forward proxy speaks for the people making requests. A reverse proxy speaks for the servers answering them.
What it does for a site
- Terminates TLS. It holds the certificate and handles HTTPS, so the apps behind it can speak plain HTTP on a private network.
- Balances load across several backend servers and stops sending traffic to one that fails.
- Caches responses and serves static files, taking work off the application.
- Compresses responses and buffers slow clients, so the backend can finish quickly and move on.
- Filters traffic, enforces rate limits and adds security headers in one place instead of in every app.
- Routes by path or hostname, so
/apican go to one service and everything else to another.
Popular reverse proxies include nginx, HAProxy, Caddy, Traefik, Envoy and Apache with mod_proxy. Content delivery networks are, in effect, large networks of reverse proxies spread around the world.
You probably need one when any of these is true: you run more than one app on a single server and want each on its own hostname or path, your app doesn't handle HTTPS well on its own, you're about to add a second application server, or you want caching and rate limits without touching application code. Even a single small app benefits, because the proxy gives you one place to manage certificates, logs and maintenance pages.
A minimal nginx setup
This config sends everything for example.com to an app listening on port 3000 on the same machine:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
What each line does:
proxy_passnames the backend. nginx forwards each request there and streams the response back.Host $hostpasses along the original hostname, so the app knows which site was requested.X-Real-IPandX-Forwarded-Forcarry the visitor's IP. Without them, every request would appear to come from nginx itself.X-Forwarded-Prototells the app whether the visitor used HTTP or HTTPS, which prevents redirect loops in apps that force HTTPS.
Test the configuration and apply it without dropping connections:
sudo nginx -t && sudo systemctl reload nginx
Adding HTTPS and a second backend
upstream app_servers {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/example.com/fullchain.pem;
ssl_certificate_key /etc/ssl/example.com/privkey.pem;
location / {
proxy_pass http://app_servers;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
The upstream block lists the backend servers. nginx sends requests to them in turn and temporarily skips one that stops responding. The certificate paths are examples, so point them at wherever your certificate tool saves its files. Keep the port 80 server block too, changed to redirect visitors to HTTPS.
Reverse proxy vs forward proxy
| Reverse proxy | Forward proxy | |
|---|---|---|
| Sits in front of | Servers | Clients |
| Set up by | The website operator | The user or their organization |
| Hides | The backend servers' addresses | The client's address |
| Clients configure it | No, they just visit the site | Yes, in the app, browser or script |
| Typical jobs | HTTPS, load balancing, caching, protection | Data collection, testing, content filtering, privacy |
| Examples | nginx, HAProxy, a CDN | Corporate web proxies, proxy services like ours |
The two often meet. When your scraper requests a page through one of our forward proxies, the site at the other end very likely answers from behind its own reverse proxy. Each one only knows about its own side of the trip.
Security basics
A reverse proxy is your site's front door, so a few habits matter:
- Don't expose the backends. Bind application servers to
127.0.0.1or a private network, so the only way in is through the proxy. - Trust forwarded headers only from your own proxy. Anyone can send a fake
X-Forwarded-Forheader, so configure your app to accept it only when the request comes from the proxy's address. If a CDN sits in front of nginx, nginx's real IP module needs to know the CDN's address ranges for the same reason. - Limit request sizes.
client_max_body_sizecaps uploads, which protects backends from oversized requests. - Keep the proxy updated. It's the part of your stack that strangers talk to first.
Troubleshooting common errors
When something goes wrong, the status code usually points to the cause:
502 Bad Gateway: nginx couldn't get a valid response from the backend. Check that the app is running and listening on the address inproxy_pass.504 Gateway Timeout: the backend took too long. Look at slow endpoints, or raiseproxy_read_timeoutif the wait is expected.- Redirect loops: the app thinks the request arrived over HTTP. Make sure it reads
X-Forwarded-Protoand trusts the proxy. - Every visitor shows the same IP in your logs: the app isn't reading
X-Forwarded-For, or doesn't trust the proxy's address. - Wrong site served: the
Hostheader isn't being passed, orserver_namedoesn't match the domain visitors use.
The HTTP status checker shows what your site returns from outside your network, and the SSL certificate checker confirms the proxy serves the right certificate for each hostname.
If you need outgoing IPs instead
People sometimes look up reverse proxies when what they need is the opposite: a way for their own scripts to send requests from different IP addresses. That's a forward proxy, and it's what we sell. Residential proxies rotate through IPs of real home connections, billed per GB from $1.00/GB. Datacenter proxies give you fast fixed IPs from $0.50/IP per 30 days. All of them work over HTTP(S) and SOCKS5, and the pricing page lists every package.