Does Eval Module work Now?
agentzh
agentzh at gmail.com
Tue Jan 11 10:25:27 MSK 2011
On Tue, Jan 11, 2011 at 4:31 AM, Sirsiwal, Umesh <usirsiwal at verivue.com> wrote:
> Thanks agentzh,
> I tried rewrite_by_lua with the following simple Lua configuration:
>
> local res = ngx.location.capture("/memc?key=" .. memc_key )
> print("copass: res " .. res.status .. ' body ' .. res.body)
>
> if res.status == 404 then
> print("copas: capture /memc_set")
> res = ngx.location.capture("/memc_set?key=" .. memc_key)
> print("copss: status " .. res.status);
> end
>
I've just tested this config snippet in my slackware linux x86_64 box
(nginx 0.8.54/0.9.3 + ngx_lua git HEAD) and it works fine. Here's the
config that I'm using:
location /memc {
set $memc_cmd get;
set $memc_key $arg_key;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
location /memc_set {
#set $memc_cmd set;
#set $memc_key $arg_key;
#memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
echo OK;
}
location /lua {
rewrite_by_lua '
local memc_key = "hello"
local res = ngx.location.capture("/memc?key=" .. memc_key )
print("copass: res " .. res.status .. " body " .. res.body)
if res.status == 404 then
print("copas: capture /memc_set")
res = ngx.location.capture("/memc_set?key=" .. memc_key)
print("copss: status " .. res.status);
end
';
content_by_lua 'return';
}
And here's the debugging outputs in my error.log:
2011/01/11 15:18:32 [info] 10985#0: *1 key: "hello" was not found by
memcached while reading response header from upstream, client:
127.0.0.1, server: localhost, request: "GET /lua HTTP/1.1",
subrequest: "/memc", upstream: "memcached://127.0.0.1:11211", host:
"localhost"
2011/01/11 15:18:32 [debug] 10985#0: *1 http wake parent request: "/lua?"
2011/01/11 15:18:32 [debug] 10985#0: *1 http posted request: "/lua?"
2011/01/11 15:18:32 [notice] 10985#0: *1 lua print: copass: res 404 body <html>
while sending to client, client: 127.0.0.1, server: localhost,
request: "GET /lua HTTP/1.1", host: "localhost"
2011/01/11 15:18:32 [notice] 10985#0: *1 lua print: copas: capture
/memc_set while sending to client, client: 127.0.0.1, server:
localhost, request: "GET /lua HTTP/1.1", host: "localhost"
2011/01/11 15:18:32 [debug] 10985#0: *1 http wake parent request: "/lua?"
2011/01/11 15:18:32 [debug] 10985#0: *1 http posted request: "/lua?"
2011/01/11 15:18:32 [notice] 10985#0: *1 lua print: copss: status 200,
client: 127.0.0.1, server: localhost, request: "GET /lua HTTP/1.1",
host: "localhost"
>
>
> I see that the subrequest was correctly issued to the /memc location. However /memc_set location subrequest was never issued.
>
Can you try out my testing config given above on your side? And paste
your complete nginx.conf and tell me which verison of nginx and
ngx_lua and what kind of operating system are you using?
Cheers,
-agentzh
More information about the nginx-devel
mailing list