我试图在我的web服务器上做一些测试,以确保反向代理在将其放在实时环境之前按预期工作,但我遇到了mod_proxy和mod_proxy_html的一些问题。
我有2个虚拟主机,一个在端口80上,另一个在端口8080上。我的目标是让对www.example.com/path/的传入请求在端口80上进入,并反向代理到端口8080。
以下是我的虚拟主机设置:<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>
我的/var/www/html/test有两个文件index.html和test.html
Test.html的内容是:
<HTML>
<BODY>
<a href="http://127.0.0.1:8080/index.html">TEST</a>
</BODY>
</HTML>
转到www.example.com/path/成功被代理并重定向到www.example.com/path/test.html,但页面上的链接仍然指向127.0.0.1。
httpd -M报告加载proxy_module和proxy_html_module
我还尝试手动添加LoadModule到http.conf
LoadModule proxy_module /usr/lib64/httpd/modules/mod_proxy.so
LoadModule proxy_html_module /usr/lib64/httpd/modules/mod_proxy_html.so
有什么想法,为什么它不能正常工作?我是否配置错误?
CentOS 7中的mod_proxy_html
包不包含任何默认的ProxyHTMLLinks
或ProxyHTMLEvents
设置,因此除非您自己提供这些设置,否则它不会做任何事情。
一种方法是将/usr/share/doc/httpd-2.4.6/proxy-html.conf
复制到/etc/httpd/conf.d/
中。该文件包含以下设置,这些设置可以使事情正常工作:
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