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