Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 2010.12.29
Fetching contributors…

Cannot retrieve contributors at this time

109 lines (83 sloc) 3.336 kb
# an example for working with the ngx_drizzle + ngx_rds_json
# modules, but you must put ngx_rds_json *after*
# ngx_eval during nginx configure, for example:
# ./configure --add-module=/path/to/nginx-eval-module \
# --add-module=/path/to/rds-json-nginx-module \
# --add-module=/path/to/drizzle-nginx-module
location = /mysql {
eval_subrequest_in_memory off;
eval_override_content_type text/plain;
eval_buffer_size 4k; # default 4k, truncated if overflown
eval $res {
drizzle_query "select * from cats";
drizzle_pass my_mysql_backend;
# now $res holds the JSON formatted result set
if ($res ~ '"Tom"') {
echo "Found the Tom cat!";
echo "The Tom cat is missing!";
# an example for working with the ngx_postgres module
location = /login {
eval_subrequest_in_memory off;
eval_override_content_type text/plain;
eval_buffer_size 1k;
eval $uid {
postgres_query "select id
from users
where name=$arg_name and pass=$arg_pass";
postgres_pass pg_backend;
postgres_output value 0 0;
if ($uid !~ '^\d+$') {
rewrite ^ /relogin redirect; break;
# your content handler settings...
This fork of ngx_eval can work with any content handlers and
even with filters enabled as long as you put ngx_eval *before*
your filter modules during nginx configure, for instance
./configure --prefix=/opt/nginx \
--add-module=/path/to/this/nginx-eval-module \
--add-module=/path/to/your/filter/module \
such that ngx_eval's filter works *after* your filter modules.
* The contents of subrequests issued from the eval block won't be
captured properly.
The following versions of Nginx should work with this module:
* 0.8.0 ~ 0.8.41, 0.8.54+ (0.8.42 ~ 0.8.53 requires patching, see below)
* 0.7.x >= 0.7.21 (last tested version is 0.7.66)
Note that nginx 0.8.42 ~ 0.8.53 won't work due to a famous regression appeared
since 0.8.42: <,103078,103078 >,
but fortunately a patch is available for nginx 0.8.53:
This one-line patch should also be able to apply cleanly to other versions
of nginx 0.8.42 ~ 0.8.53.
Nowadays we prefer ngx_lua to do the tasks originally done by ngx_eval
because of various inherent limitations in ngx_eval (and yeah, it also
requires patching the core for nginx 0.8.42+, sigh).
Here's a small example using ngx_lua:
location / {
content_by_lua '
local res = ngx.location.capture("/getbanner")
location /getbanner {
proxy_pass http://backend.local:3500;
Original ngx_eval documentation:
Documentation for this module could be found under following URLs:
* English:
* Russian:
This work is commissioned by
Jump to Line
Something went wrong with that request. Please try again.