Sub topic 4
Forward vs reverse: who knows about the proxy
This chapter assumes you know HTTP requests and headers, what an IP address, port and DNS name are, and what TLS provides. The earlier chapters introduced forward and reverse proxies separately. Here you compare them by one question: which side knows the proxy exists, and which side it works for.
The core difference
A forward proxy acts for clients. The client is configured to send its requests to the proxy, and the proxy contacts the origin server. The origin sees the proxy's address, not the client's.
A reverse proxy acts for servers. The client believes it is talking to the real site. It resolves a name, connects, and never learns that backends sit behind the address. The proxy picks a backend and relays the request.
Comparison
| Aspect | Forward proxy | Reverse proxy |
|---|---|---|
| Works on behalf of | Clients | Servers |
| Who knows about it | The client (configured or intercepted) | The server operator; clients are unaware |
| Who is hidden | The client's address from the origin | The backends' addresses from clients |
| Typical placement | Edge of a corporate or private network | In front of an application, in the server's network |
| Typical jobs | Egress filtering, access control, caching for many users | Load balancing, TLS termination, caching, routing |
| Who operates it | The client's organization | The service owner |
Reading the same request from both sides
The difference shows up in what the request looks like. With a forward proxy, the client puts the full destination in the request, because the proxy must be told where to go:
curl -x http://proxy.internal:3128 https://example.org/For HTTPS, curl first sends CONNECT example.org:443 to the proxy. With a reverse proxy, the client sends an ordinary request to the public name, and the proxy decides where it goes:
upstream app_servers {
server 10.0.0.11:8080 max_fails=3 fail_timeout=30s;
server 10.0.0.12:8080 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://app_servers;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}Nothing in the client's request mentions 10.0.0.11. The choice of backend belongs entirely to the proxy.
Whose address gets lost
Each proxy hides an address, and the hidden side may need it back.
- Behind a forward proxy, the origin sees only the proxy's IP. Origin logs and rate limits then apply to the whole proxy, not to individual users.
- Behind a reverse proxy, the backend sees the proxy as the client. The proxy must pass the original details along in headers:
X-Forwarded-For: 203.0.113.7, 10.0.0.5
X-Forwarded-Proto: https
Forwarded: for=203.0.113.7;proto=https;host=example.comChoosing between them
Ask who needs the control. If a network owner wants to control or observe what its users reach, use a forward proxy. If a service owner wants to control how traffic reaches the service, use a reverse proxy. Some deployments use both: users leave through a forward proxy, and the destination service receives them through a reverse proxy.
Exercise
A team wants all employee laptops to reach the internet only through a company-controlled gateway that blocks unapproved sites. Separately, they want one public address for their web app that spreads traffic over three servers. Which proxy type fits each need, and which side is aware of the proxy in each case?
Show answer
The first need is a forward proxy. It acts for the clients (the laptops), and the clients are configured to use it. The second need is a reverse proxy. It acts for the servers, and external clients are unaware of it because they just connect to the public address.
Exercise
A backend behind a reverse proxy logs the IP 10.0.0.5 for every request. What is happening, and which header would you use to recover the real client address?
Show answer
The backend sees the proxy's address as the connection source. Configure the proxy to set X-Forwarded-For (or the standard Forwarded header), and have the backend read the client address from it, trusting it only when the request comes from the proxy.