apache 2.4的Substitute模块使用注意

apache 2.4 的 Substitute 模块是个好东西,可以用来实时修改页面内容,做些替换什么的工作,比如

ProxyPass /  http://other_web_site.com
ProxyPassReverse / http://other_web_site.com
AddOutputFilterByType SUBSTITUTE text/html
Substitute “s|http://other_web_site.com|http://localhost|i”

可以把网页里面的 http://other_web_site.com 字样替换为 http://localhost

那么有时候 你会发现这个没生效,没法替换,但是这也没什么错误啊,
其实问题很可能是因为你proxy的那个站点用来压缩,导致在Substitute看起来页面是压缩的内容,他当然替换不了,那么必须在压缩前进行解压缩,其实并不需要解压,只需要告诉对方的服务器,我这里不接受压缩的文件,那么就需要另外一个模块了
LoadModule headers_module modules/mod_headers.so

这个模块可以更改proxy模块发到对方的header
RequestHeader set Accept-Encoding “”

那么完整就可以可以这样写

ProxyPass /  http://other_web_site.com
ProxyPassReverse /   http://other_web_site.com
RequestHeader set Accept-Encoding ""
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|http://other_web_site.com|http://localhost|i"

一共需要启用如下模块

LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule substitute_module modules/mod_substitute.so

 

附:有关nginx里面proxy的时候碰到gzip

看这里  http://www.zjpro.com/nginx-substitutions4nginx.html

 

apache 2.4的Substitute模块使用注意》上有2条评论

  1. Pingback引用通告: nginx 的 substitutions4nginx 在gzip的问题上的处理 | ZJPRO.COM

  2. Substitute “s|最佳|******|i”
    在替换中文的时候不生效是怎么回事 英文的可以

发表评论

邮箱地址不会被公开。 必填项已用*标注