Setting up mod_proxy_html on CentOS 7

给你一囗甜甜゛ 提交于 2019-12-10 11:25:19

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/32340737/setting-up-mod-proxy-html-on-centos-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!