• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H27-Oct-2017-1,201841

t/H27-Oct-2017-451366

util/H27-Oct-2017-163116

.gitattributesH A D27-Oct-201727 21

.gitignoreH A D27-Oct-2017346 4544

.travis.ymlH A D27-Oct-20171.9 KiB5949

ChangelogH A D27-Oct-201763 42

LICENCEH A D27-Oct-20171.5 KiB2524

README.mdH A D27-Oct-20177.6 KiB257188

configH A D27-Oct-2017574 2217

valgrind.suppressH A D27-Oct-20173.2 KiB169168

README.md

1Name
2====
3
4ngx_eval - Capturing subrequest response bodies into NGINX variables
5
6*This module is not distributed with the Nginx source.*
7
8Table of Contents
9=================
10
11* [Name](#name)
12* [Status](#status)
13* [Synopsis](#synopsis)
14* [Description](#description)
15    * [Use Lua instead](#use-lua-instead)
16* [Limitations](#limitations)
17* [Nginx Compatibility](#nginx-compatibility)
18* [Community](#community)
19    * [English Mailing List](#english-mailing-list)
20    * [Chinese Mailing List](#chinese-mailing-list)
21* [Bugs and Patches](#bugs-and-patches)
22* [Original ngx_eval documentation](#original-ngx_eval-documentation)
23* [Copyright and License](#copyright-and-license)
24* [See Also](#see-also)
25
26Status
27======
28
29This module is experimental and production use is discouraged.
30If you want similar (but more powerful) functionalities, see
31the [ngx_lua](http://github.com/openresty/lua-nginx-module) module instead.
32
33Synopsis
34========
35
36```nginx
37# an example for working with the ngx_drizzle + ngx_rds_json
38# modules, but you must put ngx_rds_json *after*
39# ngx_eval during nginx configure, for example:
40#     ./configure --add-module=/path/to/nginx-eval-module \
41#           --add-module=/path/to/rds-json-nginx-module \
42#           --add-module=/path/to/drizzle-nginx-module
43location = /mysql {
44    eval_subrequest_in_memory off;
45    eval_override_content_type text/plain;
46    eval_buffer_size 4k; # default 4k, truncated if overflown
47    eval $res {
48        drizzle_query "select * from cats";
49        drizzle_pass my_mysql_backend;
50        rds_json on;
51    }
52    # now $res holds the JSON formatted result set
53    if ($res ~ '"Tom"') {
54        echo "Found the Tom cat!";
55        break;
56    }
57    echo "The Tom cat is missing!";
58}
59
60# an example for working with the ngx_postgres module
61location = /login {
62   eval_subrequest_in_memory off;
63   eval_override_content_type text/plain;
64   eval_buffer_size 1k;
65   eval $uid {
66       postgres_query "select id
67           from users
68           where name=$arg_name and pass=$arg_pass";
69       postgres_pass pg_backend;
70       postgres_output value 0 0;
71   }
72   if ($uid !~ '^\d+$') {
73       rewrite ^ /relogin redirect; break;
74   }
75   # your content handler settings...
76}
77```
78
79Description
80===========
81
82This fork of ngx_eval can work with any content handlers and
83even with filters enabled as long as you put `ngx_eval` *before*
84your filter modules during nginx configure, for instance
85
86```
87./configure --prefix=/opt/nginx \
88        --add-module=/path/to/this/nginx-eval-module \
89        --add-module=/path/to/your/filter/module \
90        --add-module=/path/to/your/other/filters
91```
92
93such that `ngx_eval`'s filter works *after* your filter modules.
94
95Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the `--add-dynamic-module=PATH` option instead of `--add-module=PATH` on the
96`./configure` command line above. And then you can explicitly load the module in your `nginx.conf` via the [load_module](http://nginx.org/en/docs/ngx_core_module.html#load_module)
97directive, for example,
98
99```nginx
100load_module /path/to/modules/ngx_http_eval_module.so;
101```
102
103[Back to TOC](#table-of-contents)
104
105Use Lua instead
106---------------
107
108Nowadays, however, we prefer [ngx_lua](http://github.com/openresty/lua-nginx-module) to do the tasks originally done by `ngx_eval`
109because of various inherent limitations in `ngx_eval`.
110
111Here's a small example using ngx_lua:
112
113```nginx
114location = /filter-spam {
115    internal;
116    proxy_pass http://blah.blah/checker;
117}
118
119location / {
120    rewrite_by_lua '
121        local res = ngx.location.capture("/filter-spam")
122        if res.status ~= ngx.HTTP_OK or res.body == nil then
123            return
124        end
125        if string.match(res.body, "SPAM") then
126            return ngx.redirect("/terms-of-use")
127        end
128    ';
129
130    fastcgi_pass ...;
131}
132```
133
134this is roughly equivalent to
135
136```nginx
137location / {
138    eval $res {
139        proxy_pass http://blah.blah/checker;
140    }
141    if ($res ~ 'SPAM') {
142        rewrite ^ /terms-of-use redirect;
143        break;
144    }
145
146    fastcgi_pass ...;
147}
148```
149
150Even though the Lua example is a little longer but is much more flexible and stable.
151
152[Back to TOC](#table-of-contents)
153
154
155[Back to TOC](#table-of-contents)
156
157Limitations
158===========
159
160* The contents of subrequests issued from within the eval block
161(like those fired by echo_subrequest) won't be captured properly.
162
163[Back to TOC](#table-of-contents)
164
165Nginx Compatibility
166===================
167
168The following versions of Nginx should work with this module:
169
170* 1.9.x (last tested: 1.9.7)
171* 1.8.x
172* 1.7.x (last tested: 1.7.7)
173* 1.5.x (last tested: 1.5.12)
174* 1.4.x (last tested: 1.4.4)
175* 1.3.x (last tested: 1.3.11)
176* 1.2.x (last tested: 1.2.9)
177* 1.1.x (last tested: 1.1.5)
178* 1.0.x (last tested: 1.0.15)
179* 0.9.x (last tested: 0.9.4)
180* 0.8.0 ~ 0.8.41, 0.8.54+ (0.8.42 ~ 0.8.53 requires patching, see below) (last tested: 0.8.54)
181* 0.7.x >= 0.7.21 (last tested: 0.7.68)
182
183Note that nginx 0.8.42 ~ 0.8.53 won't work due to a [famous regression](http://forum.nginx.org/read.php?29,103078,103078) appeared
184since 0.8.42.
185
186[Back to TOC](#table-of-contents)
187
188Community
189=========
190
191[Back to TOC](#table-of-contents)
192
193English Mailing List
194--------------------
195
196The [openresty-en](https://groups.google.com/group/openresty-en) mailing list is for English speakers.
197
198[Back to TOC](#table-of-contents)
199
200Chinese Mailing List
201--------------------
202
203The [openresty](https://groups.google.com/group/openresty) mailing list is for Chinese speakers.
204
205[Back to TOC](#table-of-contents)
206
207Bugs and Patches
208================
209
210Please submit bug reports, wishlists, or patches by
211
2121. creating a ticket on the [GitHub Issue Tracker](https://github.com/openresty/nginx-eval-module/issues),
2131. or posting to the [OpenResty community](#community).
214
215[Back to TOC](#table-of-contents)
216
217Original ngx_eval documentation
218===============================
219
220Documentation for this module could be found under following URLs:
221
222* English: http://www.grid.net.ru/nginx/eval.en.html
223
224* Russian: http://www.grid.net.ru/nginx/eval.ru.html
225
226This work is commissioned by gadu-gadu.pl
227
228[Back to TOC](#table-of-contents)
229
230Copyright and License
231=====================
232
233This module is licensed under the BSD license.
234
235Copyright (C) 2009-2010, by Valery Kholodkov valery+nginx@grid.net.ru
236
237Copyright (C) 2010-2016, by Yichun "agentzh" Zhang (章亦春) <agentzh@gmail.com>, CloudFlare Inc.
238
239All rights reserved.
240
241Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
242
243* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
244
245* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
246
247THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248
249[Back to TOC](#table-of-contents)
250
251See Also
252========
253* the [ngx_lua](http://github.com/openresty/lua-nginx-module) module.
254
255[Back to TOC](#table-of-contents)
256
257