问一个很简单但是困扰我许久的问题, 我在想用lua输出当前请求的response header.
配置如下:
location /t1 {
root /data/getfile;
default_type "text-plain";
content_by_lua '
local h = ngx.resp.get_headers()
for k, v in pairs(h) do
ngx.say(k, v)
end
';
}
当我请求 http://test.domain.com/t1/t1.json 时候, 浏览器提示500错误.
nginx error log出现如下错误
lua entry thread aborted: runtime error: [string "content_by_lua"]:2: attempt to index field 'resp' (a nil value)
当我在上面用ngx.req.get_headers输出请求头信息时候没有问题的. 但是响应头就一直不行.
谢谢