Setting up mod_proxy_html on CentOS 7

bqq100 picture bqq100 · Sep 1, 2015 · Viewed 7.6k times · Source

I'm trying to do some testing on my web server to make sure reverse proxy is working as expected before putting it on a live environment, but I am running into some problems with mod_proxy and mod_proxy_html.

I have 2 virtual hosts, 1 on port 80 and 1 on port 8080. My goal is to have incoming requests for www.example.com/path/ to come in on port 80, and get reverse proxied to port 8080.

Here are my virtual host settings:

<VirtualHost *:8080>
ServerName www.example.com:8080
DocumentRoot /var/www/html/test
RewriteEngine On
RewriteCond  %{REQUEST_URI}  !^.*test
RewriteRule ^/?(.*) http://127.0.0.1:8080/test.html [R=301,L]
</VirtualHost>

<VirtualHost *:80>
ServerName www.example.com
ProxyHTMLEnable On
ProxyHTMLInterp On
ProxyPreserveHost Off
ProxyPass        /path/ http://127.0.0.1:8080/
ProxyPassReverse /path/ http://127.0.0.1:8080/
ProxyHTMLURLMap http://127.0.0.1:8080/ /path/
</VirtualHost>

My /var/www/html/test has 2 files index.html and test.html
test.html contents are:

<HTML>
<BODY>
<a href="http://127.0.0.1:8080/index.html">TEST</a>
</BODY>
</HTML>

Going to www.example.com/path/ successfully gets proxied and redirected to www.example.com/path/test.html, but the link on the page still points to 127.0.0.1.

httpd -M does report loading proxy_module and proxy_html_module
I've also tried manually adding LoadModule to http.conf

LoadModule proxy_module /usr/lib64/httpd/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib64/httpd/modules/mod_proxy_html.so

Any thoughts on why it is not working properly? Am I configuring something incorrectly?

Answer

slowdog picture slowdog · Oct 8, 2015

The mod_proxy_html package in CentOS 7 doesn't include any default ProxyHTMLLinks or ProxyHTMLEvents settings, so it does nothing unless you provide those settings yourself.

One way to do that is to copy /usr/share/doc/httpd-2.4.6/proxy-html.conf into /etc/httpd/conf.d/. That file contains the following settings, which should make things work:

ProxyHTMLLinks  a       href
ProxyHTMLLinks  area        href
ProxyHTMLLinks  link        href
ProxyHTMLLinks  img     src longdesc usemap
ProxyHTMLLinks  object      classid codebase data usemap
ProxyHTMLLinks  q       cite
ProxyHTMLLinks  blockquote  cite
ProxyHTMLLinks  ins     cite
ProxyHTMLLinks  del     cite
ProxyHTMLLinks  form        action
ProxyHTMLLinks  input       src usemap
ProxyHTMLLinks  head        profile
ProxyHTMLLinks  base        href
ProxyHTMLLinks  script      src for

ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \
                onmouseover onmousemove onmouseout onkeypress \
                onkeydown onkeyup onfocus onblur onload \
                onunload onsubmit onreset onselect onchange