使用:sub_module和substitutions4nginx-read-only

模块开发者主页:http://code.google.com/p/substitutions4nginx/

执行svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only

2017-02-26增加下载地址:git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module

下载:

编译安装时添加两个参数

--with-http_sub_module --add-module=/root/substitutions4nginx-read-only

sub_module用法:http://wiki.nginx.org/HttpSubModule

substitutions4nginx用法:http://code.google.com/p/substitutions4nginx/

s安装substitutions4nginx提示错误:-bash: svn: command not found

需安装subversion 安装命令yum -y install subversion

翻译substitutions4nginx参数:

g(default):替换所有匹配的字符串。
i: 执行不区分大小写的匹配。
o: 只需将第一个。
r: 该模式是作为一个正则表达式处理,默认是固定的字符串。

实际使用:


location / {
subs_filter '<(no?script.*?)>(.*?)<(\/no?script.*?)>' '' gi; //替换掉全部的<noscript></noscript>
subs_filter '<(s?cript.*?)>(?:\s|\S)*?<(\/s?cript.*?)>' ''  gi; //替换掉全部的<script>包换中间换行</script>
subs_filter '<(i?frame.*?)>(.*?)<(\/i?frame.*?)>' '' gi;  //替换<iframe></iframe>
}

实际测试中sub_filter比subs_filter的速度要快,但如果你开启了nginx的cache速度上可以得到改善的。

    内容分页 1 2
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。