【发布时间】:2017-02-14 13:05:25
【问题描述】:
我用 Apache 2.4 在 cento 的 7 服务器上构建了一个反向代理。它适用于标准 html 页面,但我也需要替换一些存储在 .js 文件中的 url。指令:
ProxyHTMLExtended On
应该启用对外部 .css 和 .js 文件的解析,但它不起作用。在日志文件中我可以看到:
[proxy_html:trace1] [pid 3263] mod_proxy_html.c(823): [client xxx] Non-HTML content; not inserting proxy-html filter
我尝试使用 mod_substitute,这是我的 httpd.conf 中有趣的部分:
ProxyPass /mylocation/ http://remoteserver/
<Location /mylocation/>
ProxyHTMLEnable On
ProxyHTMLExtended On
LogLevel debug proxy_html:trace3 substitute_module:debug
RequestHeader unset Accept-Encoding
AddOutputFilterByType SUBSTITUTE text/javascript text/html
Substitute "s|/css/|/mylocation/css/|ni"
Substitute "s|/js/|/mylocation/js/|ni"
Substitute "s|/custom_logo/|/mylocation/custom_logo/|ni"
Substitute "s|/html/|/mylocation/html/|ni"
Substitute "s|/current_config/|/mylocation/current_config/|ni"
Substitute "s|/web_lang/|/mylocation/web_lang/|ni"
Substitute "s|/custom_lang/|/mylocation/custom_lang/|ni"
ProxyPassReverse /
ProxyHTMLURLMap //remoteserver /mylocation/
ProxyHTMLURLMap http://remoteserver /mylocation/
ProxyHTMLURLMap /mylocation /mylocation
ProxyHTMLURLMap ^\/(.*) /mylocation/$1 R
</Location>
但在日志文件中没有任何 mod_substitute 跟踪。似乎从未调用过 mod_substitute。
proxyHTMLURLMap 规则可以正常工作,但仅适用于常规 html 文件。
根据我向服务器询问的 .js 文件,我可以在日志文件中看到:
[xml2enc:debug] [pid 3259] mod_xml2enc.c(254): [client xxx] AH01434: Charset ISO-8859-1 not supported by libxml2; trying apr_xlate
或
[proxy_html:trace1] [pid 3263] mod_proxy_html.c(823): [client xxx] Non-HTML content; not inserting proxy-html filter
然后进程停止,我收到文件但没有任何内容被替换。
1) 为什么“ProxyHTMLExtended On”规则不解析外部 .js 文件,如 Apache 文档中所述?
2) 为什么 mod_substitute 不起作用?
【问题讨论】:
-
最简单的解释是底层服务器没有发送配置中两种内容类型中的任何一种的数据。执行网络转储并从删除服务器确认内容类型标头。另外,似乎存在 libxml2 不兼容问题,您可能需要对其进行更新。
标签: substitution mod-proxy apache2.4 mod mod-proxy-html