http-eval #

ngx_eval - Capturing subrequest response bodies into NGINX variables

Source: upstream source

Directives

eval #

syntax: eval 1+ args;  ·  context: location

Captures the response body of an internal subrequest into the specified nginx variable.

eval_buffer_size #

syntax: eval_buffer_size 1 arg (size (k/m/g));  ·  context: http, server, location

Size in bytes; accepts k / m / g suffixes.

eval_escalate #

syntax: eval_escalate 1 arg (on/off flag);  ·  context: http, server, location

Boolean directive — set to "on" or "off".

eval_override_content_type #

syntax: eval_override_content_type 1 arg (string);  ·  context: http, server, location

Stores a single string value.

eval_subrequest_in_memory #

syntax: eval_subrequest_in_memory on | off;  ·  context: http, server, location

Controls whether the subrequest response used by eval is processed in memory rather than through disk buffering.

Example

# 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;
        rds_json on;
    }
    # now $res holds the JSON formatted result set
    if ($res ~ '"Tom"') {
        echo "Found the Tom cat!";
        break;
    }
    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...
}

↑ back to index