比ngx_http_substitutions_filter_module 更强大的替换模块sregex的replace-filter-nginx-module
之前写过nginx反代替换的教程(传送门),使用了ngx_http_substitutions_filter_module模块。不过这货只能替换同一行,具有局限性-_-# 现在一个更强大的替换模块来了……replace-filter-nginx-module 下面只翻译一下,再加个安装教程,因为我自己也没弄懂怎样玩= = .安装此模块需要先安装sregex运行库 apt-get update;
apt-get install git make gcc -y
#Centos改成yum
git clone https://github.com/agentzh/sregex
cd sregex
make
make install
cd ..
git clone https://github.com/agentzh/replace-filter-nginx-module
wget http://nginx.org/download/nginx-1.2.6.tar.gz
tar zxvf nginx-1.2..tar.gz
cd nginx-1.2.
./configure --add-module=../replace-filter-nginx-module #自行加其他编译参数
make
make install
nginx.conf的用法举例: location /t {
default_type text/html;
echo abc;
replace_filter 'ab|abc' X;
} location / {
# proxy_pass/fastcgi_pass/... # caseless global substitution:
replace_filter '\d+' 'blah blah' 'ig';
replace_filter_types text/plain text/css;
}
Syntax语法: ^ 匹配起始行数
$ 匹配末尾行数 \A match only at beginning of stream
\z match only at end of stream \b match a word boundary
\B match except at a word boundary . match any char
\C match a single C-language char (octet) [ab0-] character classes (positive)
[^ab0-] character classes (negative) \d match a digit character ([-])
\D match a non-digit character ([^-]) \s match a whitespace character ([ \f\n\r\t])
\S match a non-whitespace character ([^ \f\n\r\t]) \h match a horizontal whitespace character
\H match a character that isn't horizontal whitespace \v match a vertical whitespace character
\V match a character that isn't vertical whitespace \w match a "word" character ([A-Za-z0-9_])
\W match a non-"word" character ([^A-Za-z0-9_]) \cK control char (example: VT) \N match a character that isn't a newline ab concatenation; first match a, and then b
a|b alternation; match a or b (a) capturing parentheses
(?:a) non-capturing parantheses a? match or times, greedily
a* match or more times, greedily
a+ match or more times, greedily a?? match or times, not greedily
a*? match or more times, not greedily
a+? match or more times, not greedily a{n} match exactly n times
a{n,m} match at least n but not more than m times, greedily
a{n,} match at least n times, greedily a{n}? match exactly n times, not greedily (redundant)
a{n,m}? match at least n but not more than m times, not greedily
a{n,}? match at least n times, not greedily 作者信息:
Yichun “agentzh” Zhang (章亦春) agentzh@gmail.com
Syntax Supported
The following Perl 5 regex syntax features have already been implemented.
^ match the beginning of lines
$ match the end of lines
\A match only at beginning of stream
\z match only at end of stream
\b match a word boundary
\B match except at a word boundary
. match any char
\C match a single C-language char (octet)
[ab0-9] character classes (positive)
[^ab0-9] character classes (negative)
\d match a digit character ([0-9])
\D match a non-digit character ([^0-9])
\s match a whitespace character ([ \f\n\r\t])
\S match a non-whitespace character ([^ \f\n\r\t])
\h match a horizontal whitespace character
\H match a character that isn't horizontal whitespace
\v match a vertical whitespace character
\V match a character that isn't vertical whitespace
\w match a "word" character ([A-Za-z0-9_])
\W match a non-"word" character ([^A-Za-z0-9_])
\cK control char (example: VT)
\N match a character that isn't a newline
ab concatenation; first match a, and then b
a|b alternation; match a or b
(a) capturing parentheses
(?:a) non-capturing parantheses
a? match 1 or 0 times, greedily
a* match 0 or more times, greedily
a+ match 1 or more times, greedily
a?? match 1 or 0 times, not greedily
a*? match 0 or more times, not greedily
a+? match 1 or more times, not greedily
a{n} match exactly n times
a{n,m} match at least n but not more than m times, greedily
a{n,} match at least n times, greedily
a{n}? match exactly n times, not greedily (redundant)
a{n,m}? match at least n but not more than m times, not greedily
a{n,}? match at least n times, not greedily
The following escaping sequences are supported:
\t tab
\n newline
\r return
\f form feed
\a alarm
\e escape
\b backspace (in character class only)
\x{}, \x00 character whose ordinal is the given hexadecimal number
\o{}, \000 character whose ordinal is the given octal number
Escaping a regex meta character yields the literal character itself, like \{
and \.
.
Only the octet mode is supported; no multi-byte character encoding love (yet).
Installation
make
make install
Gnu make and gcc are required. (On operating systems like FreeBSD and Solaris, you should typegmake
instead of make
here.)
It will build libsregex.so
(or libsregex.dylib
on Mac OS X), libsregex.a
, and the command-line utility sregex-cli
and install them into the prefix /usr/local/
by default.
If you want to install into a custom location, then just specify the PREFIX
variable like this:
make PREFIX=/opt/sregex
make install PREFIX=/opt/sregex
If you are building a binary package (like an RPM package), then you will find the DESTDIR
variable handy, as in
make PREFIX=/opt/sregex
make install PREFIX=/opt/sregex DESTDIR=/path/to/my/build/root
If you run make distclean
before make
, then you also need bison 2.7+ for generating the regex parser files.
Synopsis
location /t {
default_type text/html;
echo abc;
replace_filter 'ab|abc' X;
} location / {
# proxy_pass/fastcgi_pass/... # caseless global substitution:
replace_filter '\d+' 'blah blah' 'ig';
replace_filter_types text/plain text/css;
} location /a {
# proxy_pass/fastcgi_pass/root/... # remove line-leading spaces and line-trailing spaces,
# as well as blank lines:
replace_filter '^\s+|\s+$' '' g;
} location /b {
# proxy_pass/fastcgi_pass/root/... # only remove line-leading spaces and line-trailing spaces:
replace_filter '^[ \f\t]+|[ \f\t]+$' '' g;
} location ~ '\.cpp$' {
# proxy_pass/fastcgi_pass/root/... replace_filter_types text/plain; # skip C/C++ string literals:
replace_filter "'(?:\\\\[^\n]|[^'\n])*'" $& g;
replace_filter '"(?:\\\\[^\n]|[^"\n])*"' $& g; # remove all those ugly C/C++ comments:
replace_filter '/\*.*?\*/|//[^\n]*' '' g;
}
比ngx_http_substitutions_filter_module 更强大的替换模块sregex的replace-filter-nginx-module的更多相关文章
- Python的regex模块——更强大的正则表达式引擎
Python自带了正则表达式引擎(内置的re模块),但是不支持一些高级特性,比如下面这几个: 固化分组 Atomic grouping 占有优先量词 Possessive quantifi ...
- summerDao-比mybatis更强大无需映射配置的dao工具
summerDao是summer框架中的一个数据库操作工具,项目地址:http://git.oschina.net/xiwa/summer. 怎么比mybatis更强大,怎么比beetlsql更简单, ...
- 使用Nginx反向代理和内容替换模块实现网页内容动态替换功能
2016年11月21日 10:30:00 xian_02 阅读数:10943 Nginx是一款轻量级高性能服务器软件,虽然轻量,但功能非常强大,可用于提供WEB服务.反向代理.负载均衡.缓存服务. ...
- zwPython,字王集成式python开发平台,比pythonXY更强大、更方便。
zwPython,字王集成式python开发平台,比pythonXY更强大.更方便. 更强大,内置opencv.cuda/opencl.NLTK自然语言.pygame游戏设计等多个重量级模块库. 更方 ...
- Excel催化剂开源第24波-较VBA更强大的.Net环境的正则表达式
在VBA上可以调用正则表达式库,从而编写正则表达式自定义函数,这个相信不少VBA开发者已经熟知,但VBA的VBScript正则表达式库毕竟是一个过时的产品,不像.Net那样是与时俱进的,所以两者实现出 ...
- 思维导图软件TheBrain 8全新发布 提供更强大的信息管理
TheBrain思维导图软件是全球唯一一款动态的网状结构的思维导图软件,广泛用于学习.演讲.项目管理.会议.需求调研与分析等.其独特的信息组织方式使得用户可以创建并连接到数以万计的数字想法,为此在全球 ...
- cVim—Chrome上更强大的vim插件
cVim——Chrome上更强大的vim插件 介绍 也许很多人在chrome上都用过类似Vimium, ViChrome的插件,这些插件的目的都差不多,就是在浏览器中提供一些类似vim的操作来提高效率 ...
- 功能更强大的格式化工具类 FormatUtils.java
package com.util; import java.text.DecimalFormat; import java.text.ParseException; import java.text. ...
- 10个工具让你的 shell 脚本更强大
10个工具让你的 shell 脚本更强大 很多人误以为shell脚本只能在命令行下使用.其实shell也可以调用一些GUI组件,例如菜单,警告框,进度条等等.你可以控制最终的输出,光标位 置还有各种输 ...
随机推荐
- IDEA启动后页面没有tomcat server选项,显示灰色问号和红叉不能使用
说明:自己好几次硬盘莫名其妙读不出来导致电脑重启后idea没有了tomcat选项,原来的tomcat上显示灰色的问号和红色小叉子,网上搜了好久加上自己摸索,终于解决了.现在记一下也分享一下,省的下回又 ...
- 分享一个.NET加密工具NetEncryptor v2.1.6(破解版)
在国外论坛闲逛,无意间看到一个.NET 加密工具.看了官网的介绍,感觉挺有意思,于是下载下来研(破)究(解)了一番. 官网地址:http://www.infralution.com/products/ ...
- 【ASP.NET MVC 学习笔记】- 12 Filter
本文参考:http://www.cnblogs.com/willick/p/3331520.html 1.Filter(过滤器)是基于AOP(Aspect-Oriented Programming 面 ...
- MongoDB正则表达式
MongoDB 使用 $regex 操作符来设置匹配字符串的正则表达式. 1. 搜索包含某关键字的内容: db.posts.find({post_text:{$regex:"w3cschoo ...
- LeetCode 414. Third Maximum Number (第三大的数)
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- 机器翻译评测——BLEU算法详解
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/7679284.html 前言 近年来,在自然语言研究领域中, ...
- ubuntu中python3.4安装pip
这两天碰到在ubuntu中安装pip的问题. 第一种方法 用百度搜索了一下,基本上都是这个命令: sudo apt-get install python3-pip 但是,用这条命令下载速度特别慢. 第 ...
- C++ new 解析重载
C++ new 解析重载 new的三种形式: (1)operator new(运算符new) (2)new operator(new 操作) (3)placement new(特殊的new操作)(不分 ...
- 网络基础二 tcp/ip协议簇 端口 三次握手 四次挥手 11种状态集
第1章 概念介绍 1.1 VLAN 1.1.1 什么是VLAN VLAN(Virtual LAN),翻译成中文是“虚拟局域网”.LAN可以是由少数几台家用计算机构成的网络,也可以是数以百计的计算机构成 ...
- 修改Jenkins用户的密码
说明:本方法仅适用于jdk6+.tomcat6+和Jenkins专有用户数据库的Jenkins! 很多童鞋在使用jenkins的时候忘记密码了,然后各种蛋疼.最近闲着无事,折腾了下.好了,闲话少扯. ...