比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组件,例如菜单,警告框,进度条等等.你可以控制最终的输出,光标位 置还有各种输 ...
随机推荐
- Vector容器构造函数
No1 vector(); No2 vector( const vector& c ); No3 explicit vector( size_type num, const TYPE& ...
- LINUX 笔记-crontab命令
用户所建立的crontab文件中,每一行都代表一项任务,每行的每个字段代表一项设置,它的格式共分为六个字段,前五段是时间设定段,第六段是要执行的命令段,格式如下: minute hour da ...
- LeetCode 268. Missing Number (缺失的数字)
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- 本表触发更新modifytime,跨表更新modifytime 触发器
一.每行有改动,则触发更新modifytime SQL> create table test(id int, name varchar(10), crdate date, udate date) ...
- js判断值为null
今天在做项目的时候,犯了一个着实不应该的错误,拿到data为null,然后判断如果为null执行A,否则执行B 我错误的代码是 if(data===null){ A; }else{ B; } 怎么调试 ...
- Linux学习(十五)LVM
一.前言 LVM,逻辑卷管理工具,它的作用是提供一种灵活的磁盘管理办法.通常我们的某个分区用完了,想要扩容,很麻烦.但是用lvm就可以很方便的扩容,收缩. 看它的原理图: 它的原理大致是:首先将磁盘做 ...
- 2017上海QCon之旅总结(下)
本来这个公众号的交流消息中间件相关的技术的.十月去上海参加了QCon,第一次参加这样的技术会议,感受挺多的,所以整理一下自己的一些想法接公众号和大家交流一下. 三天的内容还挺多的,之前已经有上篇和中篇 ...
- (11.06)Java小知识
最近由于课程变化,学习计划也跟着改动,留给我写博客的时间也越来越少.今天晚上没有课,抽空过来图书馆写一写,许久不写感觉都有点陌生了! 今天要和大季家分享的衔接了上一篇博客,是关于方法的嵌套调用与递归调 ...
- 转 html5离线储存,application cache,manifest使用体验
html5离线应用application cache 最近在APP里新增一个论坛模块,为了快速地完成,决定将整个论坛模块做成WEB APP,WEB APP最致命的就是用户体验问题,页面跳转和过多的请求 ...
- JAVAscript学习笔记 js句柄监听事件 第四节 (原创) 参考js使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...