Monday, August 13, 2012

Reverse Proxy Apache

In the world of servers its a known fact that web applications tend to slow when only one server performs everything , cost of moving to another servers tend to be great and downtime tends to become an over kill too.
    To fight with something like this people came up with the idea of reverse proxy , now reverse proxy could be imaging just like a proxy server , but unlike bywhat.com , or ninjacloak.com, reverse proxy actually grants anonymity the web application server making it impossible for user to detect which server is actually serving web applications and which one is serving static content.

Lets have a look at typical diagram:



Lets look at how it works :
 User types in something like say www.shyam.com and the code is hosted over server A1
 While Another user types something like www.techblog.com and the code is hosted over A2

Now anyone who knows anything about webserver and a little networking will tell us , that if i simply ping www.shyam.com I will get an IP belonging to A1 server and for techblog.com i will get the ip of A2 server. 

But what if i say you ping both the websites the ip will be from the proxy server ? 

Some of us have understood what i am talking about , Others are probably scratching head and going how can that happen ?

This happened because we implemented three things:
  1. pointed A name entry of both to proxy server
  2. Then set up virtual host configuration to www.shyam.com and www.techblog.com on proxy server 
  3. Made an entry in the proxy server list 
Now here is what I followed.

  1. I installed an Apache server  and put in the code in this server lets call it A1
    1. At this point , I set it up with a virtual-host configurations ( a little demostration meant for another post )
  2. I did a similar thing with A2 
  3. Then made entries in the /etc/hosts for the proxy server 
  4. Then I made a simple modification set on the server side for proxy server 

This is an entry meant for www.shyam.com

<Proxy "*">
    order deny,allow
    allow from all
</Proxy>

ProxyPass / http://www.shyam.com/
ProxyPassReverse / http://www.shyam.com/
# for IE hosts
SetEnv proxy-nokeepalive 1
ProxyPreserveHost on