lua possibilities/limitations

Richard Kearsley Richard.Kearsley at m247.com
Sun Feb 13 07:02:16 MSK 2011


Hi Guys,
I need a little help with the lua module. My ultimate aim is to import variables into nginx from outside source.
Here is my code, you can probably tell what I'm trying to do:

location /proxy {
proxy_pass http://127.0.0.1:8012/;
}

location /main {
set $myvar '';
set $limit_rate 99;
content_by_lua '
local res = ngx.location.capture("/proxy",{ args = { bla = "moo" } })
if res.status == ngx.HTTP_OK then
                                 for k,v in pairs(res.header) do
                                                  if k == "X-Limit-Rate" then
                                                                ngx.var.myvar = v
                                                 end
                                end
                                return
else
        ngx.exit(res.status)
end
';

set $limit_rate $myvar;
add_header X-Test $myvar;
add_header X-Limit $limit_rate;

}
}

The output is quite confusing:

curl -I http://localhost:101/main
HTTP/1.1 200 OK
Server: nginx/0.8.54
Date: Sun, 13 Feb 2011 03:29:00 GMT
Content-Type: application/octet-stream
Connection: keep-alive
X-Test: 100
X-Limit: 99

Am I going about this in the right way? As I say, my ultimate aim is to set a whole bunch of nginx vars from outside...

Many thanks
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20110213/eb5eae9e/attachment.html>


More information about the nginx mailing list