设定Apache的反向代理及输出内容过滤器(替换)四、配置样例及相关代码工具

这些基本都是抄袭来的

httpd-filter.conf

复制代码
ExtFilterDefine myfilter_replace_sed mode=output intype=text/html cmd="/xampp/apache/bin/sed.exe s/北京/上海/g"

ExtFilterDefine myfilter_deljs_sed mode=output 
        intype=text/html outtype=text/html 
        cmd="c:/xampp/apache/bin/sed.exe -f c:/xampp/apache/bin/deljs.sed"

ExtFilterDefine myfilter_php mode=output intype=text/html cmd="c:/xampp/php/php.exe d:/htdocs/filtertest.php"
复制代码

proxy-html.conf 在原来的基础上追加

 1 ProxyHTMLURLMap http://hanyu.baidu.com /hanyu/
 2 <Location /hanyu/>
 3     ProxyPassReverse /
 4     ProxyHTMLEnable On
 5     ProxyHTMLInterp On
 6     ProxyHTMLExtended on
 7     # SetOutputFilter  proxy-html
 8     SetOutputFilter INFLATE;proxy-html;DEFLATE
 9     ProxyHTMLURLMap http://hanyu.baidu.com /hanyu/
10     ProxyHTMLURLMap / /hanyu/
11     ProxyHTMLURLMap  /hanyu/ /hanyu/
12     #RequestHeader    unset  Accept-Encoding
13 </Location>

deljs.sed

复制代码
/<script/{
    : START;
    s#</script>#&#;
    t DEL;
    : LOOP;
    N;
    s#</script>#&#;
    t DEL;
    b LOOP;
    : DEL;
    s#<script.*</script>##;
    s#<script#&#;
    t START;
    }
复制代码


filtertest.php
1
2
3
4
5
6
7
8
9
10
<?php
# 用命令方式执行php脚本,其参数的传递规定 $avgv 为各个参数值, $avgc 为参数数量
# 使用 php://stdin 获取进程的输入数据流,然后用 file_get_contents() 写入变量
# readfile()函数读入一个文件并写入到输出缓冲,若成功,则返回从文件中读入的字节数,失败返回 false
 
$hostname $_SERVER['HTTP_HOST'];
 
# 如果 $hostname 符合条件,则处理数据,否则丢弃数据
 
$stdin file_get_contents("php://stdin");

 

sed 工具来源

https://github.com/mbuilov/sed-windows

https://sourceforge.net/projects/gnuwin32/files/sed/4.2.1
sed-4.2.1-setup.exe 包含 libintl3.dll、libiconv2.dll、regex2.dll

https://files.cnblogs.com/files/yisuo/sed.7z

原文地址:https://www.cnblogs.com/yisuo/p/14118428.html