can not get the output when i use eval module

agentzh agentzh at gmail.com
Mon Apr 18 08:15:41 MSD 2011


On Sun, Apr 17, 2011 at 10:54 PM, notedit <notedit at gmail.com> wrote:
> nginx 0.8.54  ,this is my nginx conf
>         location /one/ {
>             eval $uid {
>                 set $memc_cmd incr;
>                 set $memc_key 'system_uid';
>                 set $memc_value 1;
>                 memc_pass 127.0.0.1:11211;
>                 echo 'test';

Only one content handler is allowed in a single location. The eval
block effectively creates an anonymous location and both the memc_pass
and echo directives register a content handler in the eval block
location, which is incorrect.

Also, I'd recommend you use ngx_lua's rewrite_by_lua directive,
combined with the ngx.location.capture() lua function call to achieve
your goal, for instance:

 location = /filter-spam {
    internal;
    proxy_pass http://blah.blah/checker;
 }

 location / {
   rewrite_by_lua '
       local res = ngx.location.capture("/filter-spam")
       if res.status ~= ngx.HTTP_OK or res.body == nil then
         return
       end
       if string.match(res.body, "SPAM") then
         return ngx.redirect("/terms-of-use")
       end
   ';

   fastcgi_pass ...;
 }

this is roughly equivalent to

 location / {
    eval $res {
        proxy_pass http://blah.blah/checker;
    }
    if ($res ~ 'SPAM') {
        rewrite ^ /terms-of-use redirect;
        break;
    }

    fastcgi_pass ...;
 }

Cheers,
-agentzh



More information about the nginx mailing list