What Is a Reverse Proxy? Nginx Explained with Examples

Every time you visit a popular website, your request probably passes through a reverse proxy before it reaches the application that builds the page. The proxy is invisible to you, and that is the point. So what is a reverse proxy, in plain terms? It is a server that sits in front of one or more backend servers, accepts client requests, and forwards them to the right backend, then returns the response as if it came from the proxy itself.

This guide explains the concept, shows where it helps, compares it with a forward proxy, and ends with a working Nginx config you can adapt.

What Is a Reverse Proxy in Plain Terms

Think of a company reception desk. Visitors do not walk straight into any office; they talk to reception, which knows which department handles the request and passes it along. The visitor never learns the internal layout. A reverse proxy works the same way for web traffic: clients talk to the proxy, the proxy talks to the backend, and the client never sees the backend directly.

That separation buys several things at once. The backend stays hidden from direct attack. The proxy can serve cached or static content without bothering the app. SSL can terminate at the proxy, so backends run plain HTTP internally. And one public address can route to many internal services based on the path or hostname.

The word “reverse” distinguishes it from a forward proxy. A forward proxy sits near the client and forwards the client’s requests outward, often for filtering or anonymity. A reverse proxy sits near the server and forwards incoming requests inward. The direction of who the proxy serves is the whole difference, and mixing the two up is the most common confusion in this topic.

Forward Proxy vs Reverse Proxy

Aspect Forward proxy Reverse proxy
Sits near The client The server
Serves Clients browsing outward Backends receiving traffic
Typical uses Content filtering, anonymity Load balancing, caching, SSL termination
Client knows it exists Yes, configured in the browser No, invisible to the client

Keep this forward proxy vs reverse proxy distinction in mind when reading vendor docs, since some products use “proxy” loosely for both.

Why Use a Reverse Proxy

The first reason is security. Backends never accept direct internet traffic, so an attacker cannot probe your app server’s open ports or exploit a framework bug directly. The proxy is the only public surface, and it is a simpler, harder piece of software to attack.

The second reason is performance. A nginx reverse proxy can cache static responses, compress output, and serve many clients from one kept-alive backend connection. Those wins compound under load: fewer backend requests, less repeated work, faster responses.

The third reason is flexibility. Need to move an app to a new server? Change one proxy rule instead of updating DNS and waiting for propagation. Need to run two apps on one domain? Route /api to one backend and everything else to another. Need to take a backend down for maintenance? The proxy can serve a maintenance page while you work. Our tutorial on zero-downtime Nginx reverse proxy deployments shows how this flexibility keeps a site up during releases.

A Working Nginx Reverse Proxy Example

Here is a minimal config that proxies a domain to a local app running on port 3000, with security headers and static caching:

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;
    }

    location /static/ {
        alias /var/www/app/static/;
        expires 30d;
        add_header Cache-Control "public, immutable";
    }
}

The header lines matter. Without X-Forwarded-For, your app logs the proxy’s address for every visitor instead of the real client IP, which breaks rate limiting and analytics. The X-Forwarded-Proto header tells the app the original request was HTTPS, so it does not generate redirect loops.

These reverse proxy benefits stack: one place for TLS, one place for caching, one place for access control. If you want to compare how Nginx handles this role against Apache, our Nginx vs Apache high-traffic comparison covers the performance trade-offs in detail.

Load Balancing and When to Scale Out

When one backend is not enough, the proxy can spread traffic across several. Nginx supports round-robin by default, and you can add weights or least-connection routing:

upstream app {
    least_conn;
    server 10.0.0.1:3000;
    server 10.0.0.2:3000;
    server 10.0.0.3:3000 backup;
}

The backup server only takes traffic when the others fail, which gives you a simple failover story. Health checks in open-source Nginx are passive: a failing server is temporarily skipped after failed attempts. For active health checks and richer routing, you may eventually move to an ingress layer. Our comparison of Kubernetes ingress controllers explains when that step pays off.

Common Mistakes

  • Forgetting forwarded headers, so the app sees the proxy IP for every user
  • Proxying without timeouts, so one hung backend holds connections open
  • Caching personalized pages, so one user sees another user’s content
  • Skipping HTTPS on the proxy, leaving the public hop unencrypted

A reverse proxy is one of those pieces that feels like extra machinery until the first time it saves a deployment, absorbs a traffic spike, or hides a backend migration from your users. Start with the simple config above, add caching and load balancing only when you need them, and keep the proxy config in version control like any other code.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.