# Can not get the output when i use eval module

**URL:** <https://www.ruby-forum.com/t/can-not-get-the-output-when-i-use-eval-module/205862>\
**Category:** NGINX\
**Created:** [April 17, 2011, 4:55pm UTC](https://www.ruby-forum.com/t/can-not-get-the-output-when-i-use-eval-module/205862 "2011-04-17T16:55:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [April 17, 2011, 4:55pm UTC](https://www.ruby-forum.com/t/can-not-get-the-output-when-i-use-eval-module/205862/1 "2011-04-17T16:55:11Z")

</div>

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';

        }
        echo 'helloworld';

    }
    location /two/ {
        echo 'helloworld';
        echo_flush;
    }

```

when i use curl 127.0.0.1/two/ i can get the output ,  
but when i curl 127.0.0.1/one/ , it just stuck there, i can not get the  
output.

i checked the value of the system\_uid in memcache , it really  
changed .

what is the problem? many thanks.

–  
\*

---

<div class="post-metadata">

**Author:** ![notedit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3e96dc/32.png) [@notedit](https://www.ruby-forum.com/u/notedit)\
**Post date:** [April 18, 2011, 6:16am UTC](https://www.ruby-forum.com/t/can-not-get-the-output-when-i-use-eval-module/205862/2 "2011-04-18T06:16:21Z")

</div>

On Sun, Apr 17, 2011 at 10:54 PM, notedit [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](http://blah.blah/checker);  
}  
if ($res ~ ‘SPAM’) {  
rewrite ^ /terms-of-use redirect;  
break;  
}

```
fastcgi_pass ...;

```

}

Cheers,  
-agentzh
