PROXY vs REVERSE PROXY

Michel Milmore
4 min readAug 6, 2022
Photo by Brett Jordan on Unsplash

proxy example:

front-end request address — -> proxy middleware : take the request address and change it to a new request address — -> new requested address in the back-end setup by the proxy

example in the subscriber-form project (not the whole detailed implementation, just an overview):

in the front-end, the call is:

await axios.post("/.netlify/functions/postSubscriber", body, { headers });
// this will work for dev & prod

which, in dev, would correspond to this url:

http://localhost:3000/.netlify/functions/postSubscriber

but we want this url:

http://localhost:9000/postSubscriber
// netlify lambda serverless functions work with localhost port 9000

so, we would use a proxy middleware to go from one request url to another, with something like this for example:

— PSEUDO CODE —

1) whenever you see the string “/.netlify/functions/” in the request url:
ex.: http://localhost:3000/.netlify/functions/postSubscriber

2) change the target host to “http://localhost:9000/"
http://localhost:9000/.netlify/functions/postSubscriber

3) then rewrite the path with this regex : “^/.netlify/functions/”: “”
http://localhost:9000/postSubscriber

the code would look like this:

proxy("/.netlify/functions/", {                  // context   
target: "http://localhost:9000/", // target
pathRewrite: { "^/.netlify/functions/": ""} // rewrite
})

and there you have it, proxied to http://localhost:9000/postSubscriber.

Photo by Hunter James on Unsplash

What is a reverse proxy server?

A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. — https://www.nginx.com

A traditional forward proxy server allows multiple clients to route traffic to an external network
A reverse proxy, on the other hand, routes traffic on behalf of multiple servers — https://www.strongdm.com/

A reverse proxy ultimately forwards user/web browser requests to web servers. However, the reverse proxy server protects the web server’s identity. — https://avinetworks.com

Why is it call reverse?

As its name implies, a reverse proxy does the exact opposite of what a forward proxy does (?).
While a forward proxy proxies on behalf of clients, a reverse proxy proxies on behalf of servers. — https://www.jscape.com/ *

Photo by Tim Mossholder on Unsplash

My humble opinion:

  • A forward proxy serves the clients, and a reverse proxy serves the servers
  • What is reverse is the order of step 2–3–4 (see below)

in fwd proxies the order is: proxy -> firewall -> internet

in rev proxies the order is: internet -> firewall -> proxy

It’s only when we put them together that we see a reverse pattern (see below).

In effect, where a forward proxy hides the identities of clients, a reverse proxy hides the identities of servers. — https://www.jscape.com/

fwd proxy:

client -> proxy -> firewall -> internet -> server

// the server does not know the identity of the client, 
// the client knows the identity of the server
// the proxy knows the identity of both the client and the server

rev proxy:

client -> internet -> firewall -> proxy -> server

// the client does not know the identity of the server, 
// the server knows the identity of the client
// the proxy knows the identity of both the client and the server

both fwd and rev proxies:

client -> proxy -> firewall -> internet -> firewall -> proxy -> server

(see the reverse pattern…)

// the server does not know the identity of the client,
// the client does not know the identity of the server,
// the fwd proxy knows the identities of the client and the rev proxy
// the rev proxy knows the identities of the server and the fwd proxy

Why do we need reverse server?

This type of proxy server also moves requests strategically on behalf of web servers, typically to help increase performance, security, and reliability.
In most cases, reverse proxy servers also act as load balancers for the servers behind them. — https://avinetworks.com

In conclusion…

I think that when we think about proxy servers, we really have a reverse proxy architecture in mind.

Reverse proxies receive requests and send response typically through TCP/IP connections.

Forward proxies receive requests and send responses through internal networks.

--

--