【问题标题】:Setting up mod_proxy_html on CentOS 7在 CentOS 7 上设置 mod_proxy_html
【发布时间】:2015-11-27 05:29:27
【问题描述】:

我正在尝试在我的网络服务器上进行一些测试,以确保反向代理在将其置于实时环境之前按预期工作,但我遇到了 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

关于它为什么不能正常工作的任何想法?我是否配置错误?

【问题讨论】:

    标签: apache proxy httpd.conf mod-proxy mod-proxy-html


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 2014-09-28
      • 2014-12-02
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      相关资源
      最近更新 更多