Skip to content
Lieven Hollevoet edited this page Sep 22, 2014 · 2 revisions

Table of Contents

Reverse Proxy with Apache

Why

Reverse proxy allows you to access your mh web pages from an external site without having to expose your mh machine directly to the internet.

How

In the following diagram, the different components can be on the same machine.

``EXTERNAL USER ====> FIREWALL ====> APACHE ====> MH``

Let's assume that MH is located at 10.0.0.1:8080 and that the firewall is configured to forward requests for port 80 to the apache server.

Once we are done, mh will be accessable to all users at ``http://external.ip.address/mh/``. It is highly recommended to add some password protection to this access. See the standard Apache documentation for instructions on how to restrict access to the directive.

To get this to work, you need to get mod_proxy_html from http://apache.webthing.com/mod_proxy_html/. There is a good general tutorial at http://www.apacheweek.com/features/reverseproxies.

Here is the apache config file snippet:

code format="apache" LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule headers_module modules/mod_headers.so LoadFile /usr/lib/libxml2.so LoadModule proxy_html_module modules/mod_proxy_html.so

ProxyRequests off ProxyPass /mh/ http://10.0.0.1:8080/ ProxyHTMLURLMap http://10.0.0.1:8080 /mh

ProxyPassReverse / SetOutputFilter proxy-html ProxyHTMLURLMap / /mh/ ProxyHTMLURLMap /mh /mh RequestHeader unset Accept-Encoding

code

An Alternative How

Instead of installing mod_proxy_html, it's possible to use Apache2::ModProxyPerlHtml under mod_perl. I'm running Apache 2.2 under Centos 5.7 and I found that this is available through the package manager as perl-Apache2-ModProxyPerlHtml.noarch. Installing this with Yum also set up mod_perl in Apache, so installation was a breeze. The author of ModProxyPerlHtml claims that:

//Apache2::ModProxyPerlHtml is very simple and has far better parsing/replacement of URL than the original C code. It also support meta tag, CSS, and javascript URL rewriting and can be use with compressed HTTP. You can now replace any code by other, like changing images name or anything else.//

Installing through yum enabled all the necessary modules. Here is a copy of the config I used to proxy misterhouse through Apache.

code format="apache" RewriteEngine On

  1. Add ending '/' if not provided
RewriteCond %{REQUEST_URI} ^/misterhouse$ RewriteRule ^/(.*)$ /$1/ [R]

        PerlInputFilterHandler Apache2::ModProxyPerlHtml
        PerlOutputFilterHandler Apache2::ModProxyPerlHtml
        SetHandler perl-script
        PerlSetVar ProxyHTMLVerbose "On"
        ProxyPassReverse /
        PerlAddVar ProxyHTMLURLMap "/    /misterhouse/"
        PerlAddVar ProxyHTMLURLMap    "http://localhost:8080    /misterhouse"

code

Clone this wiki locally