Apache – Configuring A Reverse Proxy

Apache – Configuring A Reverse Proxy


A reverse proxy is a gateway for servers, and enables one web server to provide content from another transparently. As with a standard proxy, a reverse proxy may serve to improve performance of the web by caching; this is a simple way to mirror a website.

But the most common reason to run a reverse proxy is to enable controlled access from the Web at large to servers behind a firewall.
Software Requirements


In order to install Tunez the following software is required :-

1. apache 2 (Including the development package httpd-devel)
2. libxml2 (Installed as standard with Fedora Core 8)
3. mod_proxy_html-2.5.2.so

Adding mod_proxy_html and libxml2

To perform proxying Apache requires the libxml2 package and the mod_proxy_html file adding.. Where as libxml2 is installed as standard with most Operating Systems (Including Fedora Core 8) the mod_proxy_html file requires downloading and adding to Apache.

To add the mod_proxy_html file and libxml2 package to the installation perform the following steps :-

1. Download mod_proxy_html from [[http://apache.webthing.com/mod_proxy_html/mod_proxy_html-2.5.2.c apache.webthing.com]]
2. At the command prompt run the command shown below :-

apxs -c -I/usr/include/libxml2 -i mod_proxy_html-2.5.2.c

Including The Apache Proxy Modules

In order to configure Apache as a Proxy server there are several Modules which need to be enabled on the server. To ensure that the required Modules are enabled for the Apache server follow the steps below :-

1. Edit the /etc/httpd/conf/httpd.conf file and search for the Dynamic Shared Object (DSO) Support section
2. Search through the !LoadModule statements in this section for each of the lines below and uncomment by removing the # symbol at the start of the line if necessary :-

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so

3. At the bottom of the !LoadModule lines add the two lines shown below to add mod_proxy_html and libxml2 :-

LoadFile /usr/lib64/libxml2.so
LoadModule proxy_html_module modules/mod_proxy_html-2.5.2.so

4. Save and close the httpd.conf file once the above modifications have been made

Disabling Proxy Requests

To ensure that the Proxy server is not used to route unsolicited traffic disable the Proxy Requests in Apache. To disable Proxy Requests in Apache perform the following steps :-

1. Search /etc/httpd/conf/httpd.conf for the line #ProxyRequests On in the httpd.conf file and change it to the line below :-

ProxyRequests Off

2. Save and close the httpd.conf file once the above modifications have been made

Configure Reverse Proxying

To configure Reverse Proxying for an internal web server perform the following steps :-

1. Edit /etc/httpd/conf/httpd.conf and and add the following lines to the bottom of the file, substituting {http://www.example.com/} with the required internal web-site you wish to proxy and {/example/} with the folder you wish to present it as on the proxy server:-

ProxyPass {/example/} {http://www.example.com/}
ProxyHTMLURLMap {http://www.example.com} {/example}

ProxyPassReverse /
SetOutputFilter proxy-html
ProxyHTMLURLMap / {/example/}
RequestHeader unset Accept-Encoding

3. Save and close the httpd.conf file once the above modifications have been made

Refresh Apache’s Configuration

Once the modifications above have been made to the Apach config file either restart apache using service httpd restart or refresh its configuration using service httpd reload

Useful Links