nginx中利用access_by_lua_file lua/check_access.lua;脚本做访问控制检查
check_access.lua中引用lib库
local nlo = require "utility_lib"
local headers = ngx.req.get_headers()
ngx.var.headers_md5 = ngx_md5(nlo.rconcat(headers))
utility_lib.lua脚本存放一些必要的函数库,
local _M = {
_VERSION = '0.1',
re = {},
response = {}
}
function _M.rconcat(l, sep)
if type(l) ~= "table" then
return l
end
local sep = sep or ""
local res = {}
for k,v in pairs(l) do
if type(k) == "string" then
res[#res + 1] = k
end
res[#res + 1] = _M.rconcat(v, sep)
end
return table_concat(res,sep)
end
return _M
执行nginx -s reload后,发现只有一个进程大量报错,其它进程没有该错误,而且我线下环境不能复现。
2014/03/31 18:20:49 [error] 3799#0: *935869517 lua entry thread aborted: runtime error: /etc/nginx/lua/check_access.lua:54: attempt to call field 'rconcat' (a nil value)
而且该进程号3799没有其它错误日志。
不知道是不是跟我utility_Lib中没有new函数重新设置setmettable有关系?