Jan 17, 2012

Reverse Proxy in apache

Reverse Proxy Configuration in apache

Introduction:

            A reverse proxy is a gateway for servers, it can be used whenever multiple web servers must be accessible via a single public IP address. The web servers listen on different ports in the same machine, with the same local IP address or, possibly, on different machines and different local IP addresses altogether. The reverse proxy analyses each incoming call and delivers it to the right server within the local area network.

Release:
RedHat Enterprise Linux
Apache 2.x

Problem:
Configure Apache webserver as a reverse proxy server

Solution:

1)       Install the required rpm

            # yum install httpd

2)       Enable the proxy related modules in the httpd,conf file

            # vi /etc/httpd/conf/httpd.conf

LoadModule  proxy_module      modules/mod_proxy.so
LoadModule  proxy_http_module modules/mod_proxy_http.so


3)       Add the below entries to the http configuration file.

                        # vi /etc/httpd/conf/httpd.conf

            <IfModule mod_proxy.c>

            ProxyRequests Off
            <Proxy *>
            Order deny,allow
            Allow from all
            </Proxy>

            ProxyPreserveHost On
            ProxyVia On
            SSLProxyEngine on

            ProxyPass /webdav http://ServerIP:8080/webdav 
            ProxyPassReverse /webdav http://ServerIP:8080/webdav
 
            </IfModule>

Note: In the above sample all the request comes to /webdav URL redirect to the another tomcat server. For example Apache server IP is 10.0.0.1 and the tomcat server IP is 10.0.0.2, then the request like http://10.0.0.2/webdav will be redirect to http://10.0.0.2:8080/webdav

4)       To enable logging for the reverse proxy, add the below lines in the configuration file

            # vi /etc/httpd/conf/httpd.conf

            <IfModule mod_proxy.c>

            CustomLog logs/access_proxy.log combined
            ErrorLog logs/error_proxy.log

            </IfModule>

5)       Restart the httpd service

                        # /etc/init.d/httpd restart

                       



1 comment:

Anonymous said...

Thanks a lot!
This worked without any issue.