Nginx HttpSubModule sub_filter模块的过滤功能

<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<p><br /><span style="font-family: Arial;">1.使用</span><a style="font-family: Arial;" href="http://wiki.nginx.org/HttpSubModule">HttpSubModule</a><span style="font-family: Arial;">模块 </span></p> <div style="font-family: Arial;"><br /> <div>--with-http_sub_module option</div> </div> <div style="font-family: Arial;">2.Nginx JavaScript 埋点 :</div> <div style="font-family: Arial;"><span style="background-color: #f0f0f0; color: #555555; font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, Verdana, sans-serif; font-size: 14px; line-height: 17.265625px; text-align: left;"><br /></span></div> <pre style="margin: 0px 4em 2em 2em; unicode-bidi: embed; border: 3px solid #ffffff; padding: 0.5em; background-color: #f9f9f9; color: #555555; font-size: 12px; width: 986.671875px; line-height: 17.265625px; text-align: left;">location / { sub_filter &lt;/head&gt; '&lt;/head&gt;&lt;script language="javascript" src="$script"&gt;&lt;/script&gt;'; sub_filter_once on; sub_filter_types text/html; } </pre> <div style="font-family: Arial; text-align: left;"><span style="color: #555555; font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Arial, Verdana, sans-serif;"><span style="font-size: 14px; line-height: 17px;">3.</span></span>实现在IE及IE内核浏览器下,所有网站变灰色</div> <pre style="margin: 0px 4em 2em 2em; unicode-bidi: embed; border: 3px solid #ffffff; padding: 0.5em; background-color: #f9f9f9; color: #555555; font-size: 12px; width: 986.671875px; line-height: 17.265625px; text-align: left;">sub_filter ‘&lt;head&gt;’ ‘&lt;style type="text/css"&gt;html {filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); }&lt;/style&gt;&lt;/head&gt;’; </pre> <p style="margin: 0px; padding: 0px 0px 8px; text-indent: 28px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; letter-spacing: 1px; line-height: 28px;">解释:</p> <p style="margin: 0px; padding: 0px 0px 8px; text-indent: 28px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; letter-spacing: 1px; line-height: 28px;">sub_filter 一行代码前面是需要替换的内容,后面单引号内是替换成的内容。</p> <p style="margin: 0px; padding: 0px 0px 8px; text-indent: 28px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; letter-spacing: 1px; line-height: 28px;">sub_filter_once 意思是只查找并替换一次。on是开启此功能,off是关闭——默认值是on。</p> <p style="margin: 0px; padding: 0px 0px 8px; text-indent: 28px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; letter-spacing: 1px; line-height: 28px;">sub_filter_types 一行意思是选定查找替换文件类型为文本型。也可以不加此行,因为默认只查找text/html文件。</p> <p style="margin: 0px; padding: 0px 0px 8px; text-indent: 28px; color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; letter-spacing: 1px; line-height: 28px;">sub_filter模块可以用在http, server, location模块中。主要作用就是查找替换文件字符。</p> <div style="font-family: Arial; text-indent: 28px;"><span style="color: #333333; font-family: Arial, Helvetica, sans-serif;"><span style="font-size: 14px; letter-spacing: 1px; line-height: 28px;">比较实用的例子,增加</span></span>google analytics等网站分析嵌码,或全局的样式等</div> <p><span style="font-family: Arial;">PS:sub_filter Only one substitution rule per location is supported 否则会报如下错误</span></p> <div style="font-family: Arial; text-align: left;">nginx: [emerg] "sub_filter" directive is duplicate in /Dev/tengine/nginx/conf/nginx.conf:52Nginx HttpSubModule sub_filter模块的过滤功能</div>

转载于:https://my.oschina.net/loveking/blog/150112

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值