Home | Download | Documentation | Support | License |
NAMEApache2::ModProxyPerlHtml - rewrite HTTP headers and HTML links for reverse proxy usage DESCRIPTIONApache2::ModProxyPerlHtml is the most advanced Apache output filter to rewrite HTTP headers and HTML links for reverse proxy usage. It is written in Perl and exceeds all mod_proxy_html.c limitations without performance lost. Apache2::ModProxyPerlHtml is very simple and has far better parsing/replacement of URL than the original C code. It also supports meta tag, CSS, and javascript URL rewriting and can be used with compressed HTTP. You can now replace any code by other, like changing image names or anything else. mod_proxy_html can't do all of that. Since release 3.x ModProxyPerlHtml is also able to rewrite HTTP headers with Refresh url redirection and Referer. The replacement capability concern only the following HTTP content type:
other kind of file, will be left untouched (or see ProxyHTMLContentType and ProxyHTMLExcludeContentType). AVAILIBILITYYou can get the latest version of Apache2::ModProxyPerlHtml from CPAN (http://search.cpan.org/). PREREQUISITESYou must have Apache2, mod_proxy, mod_perl and IO::Compress::Zlib perl modules installed on your system. Installation on RH/CentOsInstall Apache2, apxs, the Epel repository (for mod_perl install) and the Perl Module IO::Compress:
Install ModPerl, minimal version to work with Apache 2.4 is 2.0.10:
Enable mod_perl:
The Apache module mod_ssl is not available by default, install it:
If the firewall is enabled you might want to allow access to the Apache services
Installation on Debian/UbuntuTo have Apache2 server and apxs command:
ModPerl can be installed using:
ModProxyPerlHtml need additional Perl module IO::Compress:
Enable mod_proxy:
Enable the configuration and mod_perl:
INSTALLATION
APACHE CONFIGURATIONOn Debian/Ubuntu set the following configuration into the VirtualHost section of files /etc/apache2/sites-available/default-ssl.conf and /etc/apache2/sites-available/000-default.conf. On CentOS/RedHat add it to /etc/httpd/conf.d/vhost.conf.
Note that here FilterHandlers are set globally, you can also set them in any <Location> part to set it locally and avoid calling this Apache module globally. If you want to rewrite some code on the fly, like changing images filename you can use the perl variable ProxyHTMLRewrite under the location directive as follow:
this will replace each occurence of '/logo/image1.png' by '/images/logo1.png' in the entire stream (html, javascript or css). Note that this kind of substitution is done after all other proxy related replacements. In some conditions javascript code can be replaced by error, for example:
will be rewritten like this:
To avoid the second replacement, write your JS code like that:
ModProxyPerlHTML replacement is activated on certain HTTP Content Type. If you experienced that replacement is not activated for your file type, you can use the ProxyHTMLContentType configuration directive to redefined the HTTP Content Type that should be parsed by ModProxyPerlHTML. The default value is the following Perl regular expresssion:
If you know exactly what you are doing by editing this regexp fill free to add the missing Content-Type that must be parsed by ModProxyPerlHTML. Otherwise drop me a line with the content type, I will give you the rigth expression. If you don't know about the content type, with FireFox simply type Ctrl+i on the web page. Some MS Office files may conflict with the above ProxyHTMLContentType regex like .docx or .xlsx files. The result is that there could suffer of replacement inside and the file will be corrupted. to prevent this you have the ProxyHTMLExcludeContentType configuration directive to exclude certain content-type. Here is the default value:
If you have problem with other content-type, use this directive. For example, as follow:
this regex will prevent any MS Office XML or text document to be parsed. Some javascript libraries like JQuery are wrongly rewritten by ModProxyPerlHtml. The problem is that those javascript code include some code and regex that are detected as links and rewritten. The only way to fix that is to exclude those files from the URL rewritter by using the "ProxyHTMLExcludeUri" configuration directive. For example:
Any downloaded URI that contains the given regex will be returned asis without rewritting. You can use this directive multiple time like above to match different cases. LIVE EXAMPLEHere is the reverse proxy configuration I use to give access to Internet users to internal applications:
This gives access two a webmail and webcal application hosted internally to all authentified users through their own Internet acces. There's also one acces to an Intranet portal that have links to the webcal and webmail application. Those links must be rewritten twice to works. ROT13 obfuscationSome links can be obfucated to be hidden from google or other robots. To enable encode/decode of those links you can use the ProxyHTMLRot13Links directive as follow:
All links in the page will be decoded before being rewritten and re-encoded. If obfuscation occurs on some attributs only you can set the value as a pair of element:attribut where the decoding/encoding must be applied. For example:
BUGSApache2::ModProxyPerlHtml is still under development and is pretty stable. Please send me email to submit bug reports or feature requests. COPYRIGHTCopyright (c) 2005-2020 - Gilles Darold All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. AUTHORApache2::ModProxyPerlHtml was created by :
and is currently maintain by me. |
Help support ModProxyPerlHtml |