December 5, 2026

Reverse Proxy vs Forward Proxy: Same Middleman, Opposite Sides

An empty hotel concierge desk with a brass service bell

A request sent through a forward proxy for this post arrived at the web server carrying a new header, Via: 1.1 vm (tinyproxy/1.11.1), and nothing about the client’s own address. The same kind of request sent through a reverse proxy arrived with X-Forwarded-For: 127.0.0.1 and X-Real-IP: 127.0.0.1 instead. Both proxies sat in the middle of the connection, received a request and passed it along. The difference is whose side each one is on. A forward proxy works for the client and stands in front of it. A reverse proxy works for the server and stands in front of that. Everything below came from a test with nginx 1.24.0 as a reverse proxy, tinyproxy 1.11.1 as a forward proxy and a tiny Python web app that printed every header it received.

Video: TechWorld with Nana on YouTube

Two proxies, two directions

Forward proxy: the client’s agent

A forward proxy is something the client chooses to use. A browser, a script or a whole office network is configured to send its web requests to the proxy, and the proxy fetches the pages on its behalf. The destination server sees the proxy as its visitor. Corporate web filters, caching proxies for slow links and privacy tools that hide a user’s address all work this way.

Reverse proxy: the server’s front door

A reverse proxy is something the server operator puts in place. Visitors connect to it thinking it’s the website. It receives the request and passes it to one or more back-end servers, which are often not reachable from the internet at all. Load balancers, TLS terminators, caches like a content delivery network, and the nginx instance in front of countless web apps are all reverse proxies.

The one-line test

Who configured it? If the client had to be told about the proxy, it’s forward. If the client has no idea it’s there, it’s reverse.

Five test tubes with colorful liquids in a wooden rack

What a forward proxy request looks like

The client asks differently

The forward proxy test ran tinyproxy on a local port, with curl told to use it via -x. With curl -v, the request line curl sent to the proxy was:

> GET http://127.0.0.1:18520/x HTTP/1.1
> Host: 127.0.0.1:18520
> Proxy-Connection: Keep-Alive

Notice the full URL in the request line. A normal request to a web server only names the path, /x. A request to a forward proxy names the whole destination, because the proxy needs to know where to go. The tinyproxy log recorded the same thing: Request (file descriptor 5): GET http://127.0.0.1:18520/x HTTP/1.1, followed by Established connection to host "127.0.0.1".

What the server received

The back-end app printed:

Host: 127.0.0.1:18520
Connection: close
Via: 1.1 vm (tinyproxy/1.11.1)
User-Agent: demo

tinyproxy added a Via header naming itself. It did not add anything saying who the original client was. From the server’s point of view, the request came from the proxy, which is exactly what a privacy-focused forward proxy is meant to achieve.

HTTPS through a forward proxy

For HTTPS, a forward proxy can’t read the request at all. The client sends a CONNECT request asking the proxy to open a raw tunnel to the destination, and then runs TLS through that tunnel end to end. The proxy sees the hostname and port and moves encrypted bytes; the page contents stay private between the browser and the site. Filtering proxies that inspect HTTPS have to break this model by installing their own certificate authority on every client.

A test that almost lied

One detail from the setup is worth passing on. The first forward-proxy test appeared to work even with tinyproxy stopped. The test environment’s no_proxy variable listed 127.0.0.1, so curl was quietly going direct. Passing --noproxy '' to override it made curl actually use the proxy, and with the proxy stopped it then failed with Couldn't connect to server, as it should. A proxy test that passes without the proxy running isn’t testing the proxy.

What a reverse proxy request looks like

The nginx configuration

The reverse proxy test put nginx in front of the same Python app:

location / {
    proxy_pass http://app;
    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 the back end saw

Host: 127.0.0.1
X-Real-IP: 127.0.0.1
X-Forwarded-For: 127.0.0.1
X-Forwarded-Proto: http
User-Agent: demo

The client simply asked for /hello on the reverse proxy’s address; it never knew a second server existed. The back end, meanwhile, received headers describing the original visitor.

Without those headers

A second location in the same config used a bare proxy_pass with no extra headers. The app saw Host: app, the name of the nginx upstream block, and no client address at all. Every request appeared to come from the proxy itself. Applications that log visitors, rate-limit by address or build absolute URLs break in confusing ways when a reverse proxy is added without these lines.

Spreading the load

Because the client never talks to the back end directly, a reverse proxy can quietly spread requests across several servers. A second nginx test defined an upstream pool with two copies of a small app on different ports, each replying with its own port number. Four requests in a row came back alternating: 18541, 18542, 18541, 18542. That’s nginx’s default round-robin behavior.

Then one back end was stopped. The next four requests all came back from 18541, with no errors returned to the client. nginx tried the dead server, failed to connect, and passed the request to the surviving one. From the visitor’s side, nothing happened at all. That’s the core of what a load balancer does, and it’s why even small self-hosted setups sometimes run two copies of an app behind one reverse proxy: one can be restarted or upgraded while the other keeps serving.

A forward proxy can’t do this for a website, because it doesn’t know or control what’s behind the destination address. It can only choose how the client’s request goes out.

Opened envelopes

X-Forwarded-For, and why it can lie

How the header grows

MDN’s reference on X-Forwarded-For describes it as “a de-facto standard header for identifying the originating IP address of a client connecting to a web server through a proxy server.” Its syntax is a list: X-Forwarded-For: <client>, <proxy>, …, <proxyN>. nginx’s $proxy_add_x_forwarded_for variable, as the nginx wiki’s page on forwarding headers puts it, exists “to automatically append $remote_addr to any incoming X-Forwarded-For headers.”

A forged first entry

That appending is the catch. The test sent a request to the reverse proxy with a made-up header, X-Forwarded-For: 6.6.6.6. The back end received:

X-Forwarded-For: 6.6.6.6, 127.0.0.1

The client’s invented address went first, followed by the real one nginx appended. An application that naively trusts the first entry in the list would believe the request came from 6.6.6.6. MDN’s security section states that the header “is untrustworthy when no trusted reverse proxy (e.g., a load balancer) is between the client and server,” and that improper parsing “can result in spoofed values being used for security-related purposes.”

Reading it safely

The trustworthy entries are the ones added by proxies the operator controls, which means reading the list from the right-hand end. With a single reverse proxy that faces the internet directly, the last entry is the real client. Alternatively, the edge proxy can replace the header instead of appending, setting X-Forwarded-For $remote_addr so a client can’t seed it. The standardized alternative is the Forwarded header from RFC 7239, which MDN notes is “much less frequently used.”

When each one is the right tool

Forward proxies in a home lab

A forward proxy makes sense when many machines need controlled or cached access out to the internet: a lab network where only one host may reach the outside, a caching proxy for package downloads shared by several build machines, or a filter for a family network. tinyproxy’s configuration for the test was six lines, with an Allow 127.0.0.1 line so nobody else could use it. Leaving a forward proxy open to the internet turns it into a free relay for strangers.

Reverse proxies in a home lab

A reverse proxy is the standard way to put several self-hosted services behind one address and one certificate: a media server, a wiki and a dashboard, each reached by its own hostname, while the back-end apps listen only on internal addresses. It’s also where TLS is usually terminated, so certificates are managed in one place.

Using both at once

The two can stack. A final test sent a request through tinyproxy to the nginx reverse proxy. The back end saw both sets of fingerprints: tinyproxy’s Via: 1.1 vm (tinyproxy/1.11.1), passed along by nginx, and nginx’s own X-Forwarded-For: 127.0.0.1 and X-Real-IP: 127.0.0.1, carrying the forward proxy’s address as the “client.” From the server’s side, the forward proxy is the visitor, and from the client’s side, the reverse proxy is the website. Each middleman only knows about the hop on either side of it. That’s worth remembering when reading logs: an address in a log line is only ever the last hop, unless a proxy the operator trusts wrote down the one before it.

Glass entrance doors labeled B2 with a media entrance sign

Sources

  • MDN Web Docs, “X-Forwarded-For”: https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Forwarded-For
  • MDN Web Docs, “Forwarded”: https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Forwarded
  • NGINX wiki, “Using the Forwarded header”: https://nginx.com/resources/wiki/start/topics/examples/forwarded/

920 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *