Saturday, March 29, 2014

Lets Reverse the Proxy !

Acc to Wikipedia:

A reverse proxy is a type of web server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client as though they originated from the server itself.

So, basically a reverse proxy does the exact opposite of what a forward proxy does. While a forward proxy proxies in behalf of clients (or requesting hosts), a reverse proxy proxies in behalf of servers. A reverse proxy accepts requests from external clients on behalf of servers stationed behind it.

Some of the reasons why do we need proxy servers:

  • A server wants to force all its traffic to pass through a certain server before.
Say, you have a large web site that millions of people want to see, but a single web server cannot handle all the traffic. So you what you can do is
set up many servers, and put a reverse proxy on the internet that will send users to the server closest to them when they try to visit your site.
This is part of how the Content Distribution Network (CDN) concept works.
It also helps in load balancing.

  • You do not want to expose your server directly to the public.
  • Spoon Feeding:  a dynamically generated page can be produced all at once and served to the reverse-proxy, which can then return it to the client a little bit at a time. The program that generates the page need not remain open, thus releasing server resources during the possibly extended time the client requires to complete the transfer.

Lets jump to a practical example now.

We have a local server in IIIT, which is used for displaying the transcript/grades to the students, after filling their login credentials.

Now, when you are not in the IIIT netowrk, you can not access that server. This is an issue I had been facing from the first year, since mostly the grades come out in vacation time and we all are not in the campus.

Reverse proxy comes to the rescue here:

In our college, each student is provided with their own server on is
This server is inside the IIIT network but is accessible from outside.

So, what I did is, set up my web.iiit server as a reverse proxy server for the isas server.

The workflow is:

It basically contains a php script, that takes your login credentials and requests isas server on behalf of your system.
In the first response, the isas server responds with a brief response with some cookies. These cookies are used in the next request to get a detailed response of the transcript.

Link to the Code :

I have used Curl library. There can be many other options.

Feel free to use the code and report any issues.

Cheers !

No comments: