Thursday, October 9, 2014

Reverse Proxy configuration in Apache

A Reverse Proxy is a type of server that retrieves resources from other servers on behalf of the client. The resources are returned to the client as though they are originated from the server itself. Client feels that the resources are being provided by the server itself, and unaware of the servers that have provided the resources.Forward proxy acts as an intermediary for its clients and returns the resources accessible on the internet.Reverse proxy acts as an intermediary for the servers to return the resources provided by other servers.Reverse proxy is most widely used when you want your application accessible in the internet, without exposing the Application Servers, in other words, it is used when you want your intranet application to be accessible through internet.The proxied server may be a webserver itself, or it may be an application server using a different protocol, or an application server.


How to configure Reverse Proxy in Apache ?

  • Below Modules developed for Reverse proxy configuration in Apache
    • proxy_module               mod_proxy.so
    • proxy_http_module       mod_proxy_http.so  
  • Load the modules in httpd.conf file as below
    • LoadModule proxy_module       modules/mod_proxy.so
    • LoadModule proxy_http_module  modules/mod_proxy_http.so
  • Add the below configuration lines in httpd.conf file
             <Location /Reverse_Proxy/>
                   ProxyPass                http://backenserver.com/Reverse_Proxy/
                  ProxyPassReverse   http://backenserver.com/Reverse_Proxy/
            </Location>

Note: If Virtual hosts configured in Apache webserver place the above block of statements in Virtual host block.

<VirtualHost *:80>
          ServerName  myserver.com
    <Location /Reverse_Proxy/>
          ProxyPass                http://backenserver.com/Reverse_Proxy/
          ProxyPassReverse   http://backenserver.com/Reverse_Proxy/
     </Location>
</VirtualHost>

How Reverse Proxy Works ?

When request comes to Apache webserver it  checks for the context path in httpd.conf file and takes the  back end server information in Reverse proxy configuration block .Reverse Proxy module  sends the request to the back end (proxy server) and get the response from back end server and give to the client.

Is Context Path in Location tag and Context path of Back end server Should be same ?
No need to be same. We can change the context path in the Location tag as per our requirements.

Note: Back end server Context Path Should be valid one otherwise we wont get the results.

<VirtualHost *:80>
           ServerName  myserver.com
    <Location /Test_Reverse_Proxy/>
          ProxyPass                http://backenserver.com/Reverse_Proxy/
          ProxyPassReverse   http://backenserver.com/Reverse_Proxy/
     </Location>
</VirtualHost>
  • http://myserver.com/Test_Reverse_Proxy
  • http://myserver.com/Reverse_Proxy
 Both URL's gives the same results because both are accessing same back end servers

Note: Apache modules are Operating System's Specific so we should  load the Apache OS Specific Modules.

No comments:

Post a Comment