Guide 5 min read Updated

How a reverse proxy works

What a reverse proxy does for a website, a minimal nginx setup you can adapt, and why it's a different tool from the proxies you'd buy for outgoing traffic.

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 /api can 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_pass names the backend. nginx forwards each request there and streams the response back.
  • Host $host passes along the original hostname, so the app knows which site was requested.
  • X-Real-IP and X-Forwarded-For carry the visitor's IP. Without them, every request would appear to come from nginx itself.
  • X-Forwarded-Proto tells 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.1 or 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-For header, 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_size caps 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 in proxy_pass.
  • 504 Gateway Timeout: the backend took too long. Look at slow endpoints, or raise proxy_read_timeout if the wait is expected.
  • Redirect loops: the app thinks the request arrived over HTTP. Make sure it reads X-Forwarded-Proto and 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 Host header isn't being passed, or server_name doesn'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.

Questions, answered

What is a reverse proxy used for?
It accepts requests for a website and passes them to the servers behind it. Along the way it can handle HTTPS, balance load, cache responses, compress content and filter bad requests.
Is a load balancer a reverse proxy?
Most HTTP load balancers are reverse proxies, because they receive client requests and forward them to backend servers. A reverse proxy doesn't have to balance load, though, and it can sit in front of a single server.
Can I use a reverse proxy to hide my IP when browsing?
No. A reverse proxy protects servers, not visitors. To change the IP address your own requests come from, you need a forward proxy.
What is the difference between a reverse proxy and a CDN?
A CDN is a network of reverse proxies spread across many locations, usually with caching built in. A single reverse proxy usually runs close to the servers it protects.

Real IPs, fresh and clean.

Residential, mobile, ISP and datacenter proxies on one crypto balance. Start with one GB or one IP. No KYC.

  • Real IPs
  • Fresh, clean
  • No KYC
  • Crypto