Skip to content
Log In Sign Up info@muvcloud.com

The Short Answer

An application such as a Node.js or Python service listens on a local port, for example 127.0.0.1:3000. A web server such as Nginx listens on ports 80 and 443, handles HTTPS, and forwards requests to that local port. The application never faces the internet directly. HAProxy is another common reverse proxy, often chosen when load balancing is the main job.

Reverse Proxy vs Forward Proxy

Forward proxyReverse proxy
Acts forClientsServers
Set up byThe client's networkThe site operator
HidesThe clientThe backends
Typical useFiltering outbound trafficHTTPS, routing, caching

The traffic flows the same way; what differs is whose side the proxy is on.

What a Reverse Proxy Does

  • TLS termination: it holds the certificate and handles HTTPS, so backends speak plain HTTP on a local or private address. See what is SSL/TLS.
  • Routing: one public address serves many applications, chosen by host name or path, such as /api/ to one backend and everything else to another.
  • Load balancing: requests are spread across several backends; see what is a load balancer.
  • Caching and compression: it can store responses and compress them, which takes load off the application.
  • Buffering: it can read slow clients' requests completely before passing them on, so the backend is not held up.
  • Limits: request size, rate limits, and access rules in one place.

A Minimal Example

server {
    listen 443 ssl;
    server_name example.com;
    # ssl_certificate and ssl_certificate_key lines go here

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

The full setup, with certificates and testing, is in Nginx reverse proxy.

The Real Client Address

To the backend, every request comes from the proxy, so its logs show 127.0.0.1 or the proxy's private address. The proxy passes the original details in headers:

  • X-Forwarded-For: the client address, plus any earlier proxies.
  • X-Real-IP: the client address alone, a common Nginx convention.
  • X-Forwarded-Proto: whether the client used http or https.
  • Forwarded: the standardized header that combines these.

The backend must trust these headers only when they come from the proxy, because any client can send them. In Nginx on a backend, the realip module does this with set_real_ip_from naming the proxy's address and real_ip_header naming the header. A proxy that forwards raw TCP instead of HTTP can pass the address with the PROXY protocol.

On Your Server: See the Proxy at Work

sudo ss -tlnp
curl -I https://example.com
curl -I http://127.0.0.1:3000
  • Listening sockets: Nginx should appear on 0.0.0.0:443 and the application on 127.0.0.1:3000. If the application shows 0.0.0.0:3000, it is reachable around the proxy; bind it to 127.0.0.1.
  • Headers: compare the two curl -I results. Headers that appear only in the first were added by the proxy.
  • Logs: follow /var/log/nginx/access.log and the application's log side by side while you load a page; see Nginx logs.

Common Problems

  • 502 Bad Gateway: the backend is down or on another port; see 502 Bad Gateway in Nginx.
  • 504 Gateway Timeout: the backend answered too slowly; see 504 Gateway Timeout.
  • Redirect loop: the application thinks the request was plain HTTP because it ignores X-Forwarded-Proto; see too many redirects.
  • Every visitor has the same address: the headers are not set or not trusted on the backend.
  • One server, one point of failure: if the proxy stops, every site behind it stops. Monitor it and test each change with sudo nginx -t before reloading.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations