如何解决Nginx / Lua表现异常
我是Lua新手,我试图从Lua调用共享对象(执行代码),该对象基本上是身份验证代码,如果验证成功,则路由发生到上游,否则抛出了禁止,但是,我看到了奇怪的行为,每当在Nginx重新加载后执行CURL时,身份验证都会成功进行,并且Nginx会路由到上游,但是随后的每个CURL都会导致以下错误。
020/08/14 15:12:53 [error] 187#187: *18 lua entry thread aborted: runtime error:
/usr/local/openresty/nginx/auth.lua:18: cannot change a protected metatable
stack traceback:
coroutine 0:
Auth.lua文件
-- auth.lua
local ffi = require("ffi")
local im = ffi.load("/lib.so")
ffi.cdef([[
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef struct { const char *p; GoInt n; } GoString;
extern GoInt VerifyToken(GoString p0);
]]);
local accessToken = string.sub(ngx.var.http_Authorization,8)
local typeString = ffi.metatype("GoString",{})
--- above line throwing error ^^^^
local accessTokenString= typeString(accessToken,string.len(accessToken))
local result = im.VerifyToken(accessTokenString)
if tonumber(result)==1LL then
-- we are ok here and proceed to route to upstream
else
ngx.exit(ngx.HTTP_FORBIDDEN)
end
有人可以告诉我这是什么问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。