首页 文章

在CentOS 7上设置mod_proxy_html

提问于
浏览
1

我正在尝试在我的Web服务器上进行一些测试,以确保反向代理在将其置于实时环境之前按预期工作,但我遇到了mod_proxy和mod_proxy_html的一些问题 .

我有2个虚拟主机,1个在端口80上,1个在端口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有2个文件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

为什么它不能正常工作的任何想法?我配置错误了吗?

1 回答

  • 3

    CentOS 7中的 mod_proxy_html 软件包不包含任何默认的 ProxyHTMLLinksProxyHTMLEvents 设置,因此除非您自己提供这些设置,否则它不会执行任何操作 .

    一种方法是将 /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
    

相关问题