找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 9523|回复: 0

可替换多行的nginx反代替换模块

[复制链接]
发表于 2015-10-31 09:41:01 | 显示全部楼层 |阅读模式
比ngx_http_substitutions_filter_module 更强大的替换模块:replace-filter-nginx-module) t( P5 }7 M) l: w
这家伙能替换多行文本!# m% b/ k- x7 B- V+ O2 W
6 e% J$ j$ I) |. I. P& m# l
下面只翻译一下,再加个安装教程,因为我自己也没弄懂怎样玩= =- e$ }3 }4 ~3 f, ^5 _0 `
; D9 q( L  ?6 q6 g& {4 f$ y0 U& h
1.安装此模块需要先安装sregex运行库
  Z7 y5 d& s# f/ d8 u+ S. y2 a8 d- \) O& ]0 H: ~9 l, h
[AppleScript] 纯文本查看 复制代码
apt-get update;apt-get install git make gcc -y  #Centos改成yum
git clone https://github.com/agentzh/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.6.tar.gz
cd nginx-1.2.6
./configure --add-module=../replace-filter-nginx-module  #自行加其他编译参数
make 
make install
9 @3 r$ K. y( U$ W: ^5 _' ~: d& s
nginx.conf的用法举例:/ q% \7 I( v% Y* U* k3 K9 m
[AppleScript] 纯文本查看 复制代码
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;
}
7 q8 P: c3 O, E$ Y2 y4 H5 q
Syntax语法:
3 L) t; F/ V) a% U" e- {" G
[AppleScript] 纯文本查看 复制代码
^             匹配起始行数
$             匹配末尾行数

\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
& d& ]/ S, m! B; b" t
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|第一站论坛 ( 蜀ICP备06004864号-6 )

GMT+8, 2024-9-8 09:00 , Processed in 0.066066 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表