Forward Proxy Using Apache



There are many scenarios where we need some kind of proxy. We will consider one scenario from all where we need to use the forward proxy.


Case :


Suppose there is a service which is available for certain IP/ IPs only (These are mostly secured services). In this case, you have to forward the service requests through that specific. 

Take an example :

Entities playing role,
  • Hosting App On Google App Engine ( Dynamic IP)
  • White Listed Server ( X.X.X.X )
  • Resource Server ( Y.Y.Y.Y )
Here Resource  Server ( Y.Y.Y.Y ) will just respond to the request come from the White Listed IP Server ( X.X.X.X ).

So if we want to request  Resource Server (Y.Y.Y.Y) we have to send it to the way Server feel like they have come from White Listed Server IP (X.X.X.X).

Here Proxy server comes in the play.
Proxy server takes the request and forwards it as they are initiated by itself.
So what we have to do is we have to put a proxy server at White Listed Server.

Next,

Our App will send request through the white listed server instead of directly requesting the Resource server

To setup Proxy server in apache 

create a new virtual host file

Example

<VirtualHost *:80>
 ServerName test.app
        <IfModule mod_proxy.c>
     ProxyRequests On
     ProxyVia On
     <Proxy *>
        Order deny,allow
        Allow from all
  </Proxy>
  ProxyPass / http://www.google.com  
          ProxyPassReverse  / http://www.google.com 
  LogLevel debug
        </IfModule>
</VirtualHost>


In the upper example. Every Request made to test.app server on port 80 with root URL it will be forwarded to URL www.google.com.

Template


<VirtualHost *:80>
 ServerName [servername] 
        <IfModule mod_proxy.c>
     ProxyRequests On
     ProxyVia On
     <Proxy *>
        Order deny,allow
        Allow from all
  </Proxy>
  ProxyPass [Path-From-Requsting-Server]  [URL-Request-Need-To-Call-On-Resource-Server]
  ProxyPassReverse  [Path-From-Requsting-Server]  [URL-Request-Need-To-Call-On-Resource-Server]
  LogLevel debug
        </IfModule>
</VirtualHost>

Comments

Popular Posts