README
1nginx_substitutions_filter
2 *Note: this module is not distributed with the Nginx source.
3 Installation instructions can be found below.*
4
5 Description
6 nginx_substitutions_filter is a filter module which can do both regular
7 expression and fixed string substitutions on response bodies. This
8 module is quite different from the Nginx's native Substitution Module.
9 It scans the output chains buffer and matches string line by line, just
10 like Apache's mod_substitute
11 (<http://httpd.apache.org/docs/trunk/mod/mod_substitute.html>).
12
13 Example
14 location / {
15
16 subs_filter_types text/html text/css text/xml;
17 subs_filter st(\d*).example.com $1.example.com ir;
18 subs_filter a.example.com s.example.com;
19 subs_filter http://$host https://$host;
20 }
21
22 Directives
23 * subs_filter_types
24
25 * subs_filter
26
27 subs_filter_types
28 syntax: *subs_filter_types mime-type [mime-types] *
29
30 default: *subs_filter_types text/html*
31
32 context: *http, server, location*
33
34 *subs_filter_types* is used to specify which content types should be
35 checked for *subs_filter*, in addition to *text/html*. The default is
36 only *text/html*.
37
38 This module just works with plain text. If the response is compressed,
39 it can't uncompress the response and will ignore this response. This
40 module can be compatible with gzip filter module. But it will not work
41 with proxy compressed response. You can disable the compressed response
42 like this:
43
44 proxy_set_header Accept-Encoding "";
45
46 subs_filter
47 syntax: *subs_filter source_str destination_str [gior] *
48
49 default: *none*
50
51 context: *http, server, location*
52
53 *subs_filter* allows replacing source string(regular expression or
54 fixed) in the nginx response with destination string. The variables
55 in matching text is only avaiable under fixed string mode, which means
56 the matching text could not contain variables if it is a regular
57 expression. Substitution text may contain variables. More than one
58 substitution rules per location is supported.
59 The meaning of the third flags are:
60
61 * *g*(default): Replace all the match strings.
62
63 * *i*: Perform a case-insensitive match.
64
65 * *o*: Just replace the first one.
66
67 * *r*: The pattern is treated as a regular expression, default is
68 fixed string.
69
70 subs_filter_bypass
71 syntax: *subs_filter_bypass $variable1 ...*
72
73 default: *none*
74
75 context: *http, server, location*
76
77 You can sepcify several variables with this directive. If at least one
78 of the variable is not empty and is not equal to '0', this substitution
79 filter will be disabled.
80
81 Installation
82 To install, get the source with subversion:
83
84 git clone
85 git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
86
87 and then compile nginx with the following option:
88
89 ./configure --add-module=/path/to/module
90
91 Known issue
92 * Can't substitute the response header.
93
94 CHANGES
95 Changes with nginx_substitutions_filter 0.6.4 2014-02-15
96
97 * Now non-200 response will work
98
99 * added the subs_filter_bypass directive
100
101 Changes with nginx_substitutions_filter 0.6.2 2012-08-26
102
103 * fixed a bug of buffer overlap
104
105 * fixed a bug with last zero buffer
106
107 Changes with nginx_substitutions_filter 0.6.0 2012-06-30
108
109 * refactor this module
110
111 Changes with nginx_substitutions_filter 0.5.2 2010-08-11
112
113 * do many optimizing for this module
114
115 * fix a bug of buffer overlap
116
117 * fix a segment fault bug when output chain return NGX_AGAIN.
118
119 * fix a bug about last buffer with no linefeed. This may cause segment
120 fault. Thanks for Josef Fr�hle
121
122 Changes with nginx_substitutions_filter 0.5 2010-04-15
123
124 * refactor the source structure, create branches of dev
125
126 * fix a bug of small chunk of buffers causing lose content
127
128 * fix the bug of last_buf and the nginx's compatibility above 0.8.25
129
130 * fix a bug with unwanted capture config error in fix string
131 substitution
132
133 * add feature of regex captures
134
135 Changes with nginx_substitutions_filter 0.4 2009-12-23
136
137 * fix many bugs
138
139 Changes with nginx_substitutions_filter 0.3 2009-02-04
140
141 * Initial public release
142
143 Reporting a bug
144 Questions/patches may be directed to Weibin Yao, yaoweibin@gmail.com.
145
146 Copyright & License
147 This module is licensed under the BSD license.
148
149 Copyright (C) 2014 by Weibin Yao <yaoweibin@gmail.com>.
150
151 All rights reserved.
152
153 Redistribution and use in source and binary forms, with or without
154 modification, are permitted provided that the following conditions are
155 met:
156
157 *
158 Redistributions of source code must retain the above copyright
159
160 notice, this list of conditions and the following disclaimer.
161
162 *
163 Redistributions in binary form must reproduce the above copyright
164
165 notice, this list of conditions and the following disclaimer in the
166 documentation and/or other materials provided with the distribution.
167
168 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
169 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
170 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
171 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
172 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
173 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
174 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
175 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
176 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
177 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
178 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
179
180