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 (将#修改为@)