nginx 无法使用OPM(OpenResty)中的库

hkmswyz6  于 2023-06-21  发布在  Nginx
关注(0)|答案(1)|浏览(181)

我是OpenResty的新手,我试图使用lua-resty-radixtree库,我遇到了一个错误:

Hello User!
ERROR: /usr/local/openresty/site/lualib/resty/radixtree.lua:102: /usr/local/openresty/site/lualib/librestyradixtree.so
/usr/local/openresty/lualib/librestyradixtree.so
./librestyradixtree.so
/usr/local/lib/lua/5.1/librestyradixtree.so
/usr/local/openresty/luajit/lib/lua/5.1/librestyradixtree.so
/usr/local/lib/lua/5.1/librestyradixtree.so
tried above paths but can not load librestyradixtree.so
stack traceback:
        /usr/local/openresty/site/lualib/resty/radixtree.lua:102: in main chunk
        [C]: in function 'require'
        lua/hello.lua:3: in function 'file_gen'
        init_worker_by_lua:45: in function <init_worker_by_lua:43>
        [C]: in function 'xpcall'
        init_worker_by_lua:52: in function <init_worker_by_lua:50>

下面是Lua代码:

ngx.say("Hello User!")

local radix = require("resty.radixtree")
        local rx = radix.new({
            {
                paths = {"/aa", "/bb*", "/name/:name/*other"},
                hosts = {"*.bar.com", "foo.com"},
                methods = {"GET", "POST", "PUT"},
                remote_addrs = {"127.0.0.1","192.168.0.0/16",
                                "::1", "fe80::/32"},
                vars = {
                    {"arg_name", "==", "json"},
                    {"arg_weight", ">", 10},
                },
                filter_fun = function(vars, opts)
                    return vars["arg_name"] == "json"
                end,

                metadata = "metadata /bb",
            }
        })

        -- try to match
        local opts = {
            host = "foo.com",
            method = "GET",
            remote_addr = "127.0.0.1",
            vars = ngx.var,
        }
        ngx.say(rx:match("/aa", opts))

        -- try to match and store the cached value
        local opts = {
            host = "foo.com",
            method = "GET",
            remote_addr = "127.0.0.1",
            vars = ngx.var,
            matched = {}
        }
        ngx.say(rx:match("/name/json/foo/bar/gloo", opts))
        ngx.say("name: ", opts.matched.name, " other: ", opts.matched.other)

Nginx配置:

pid logs/nginx.pid;
events {
  worker_connections 1024;
}

http {
  server {
    listen 8080;
    location / {
      content_by_lua_file lua/hello.lua;
      }
    }
  }

我已经通过OPM安装了库,方法是运行:

sudo opm get xiangnanscu/lua-resty-radixtree
sudo opm get xiangnanscu/lua-resty-expr
sudo opm get xiangnanscu/lua-resty-ipmatcher

查看这个问题,我发现OpenResty在这个路径/usr/bin/openresty下,而Lua库正在/usr/local/openresty文件夹中搜索.so文件,如错误中所示。
我试着在nginx.conf文件中设置它,但它没有改变任何东西:

lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";

你知道是什么问题以及如何解决它吗?先谢谢你了!

vulvrdjw

vulvrdjw1#

您尝试使用的xiangnanscu/lua-resty-radixtree软件包 * 不是官方的 *(它源自this fork),并且实际上不包含librestyradixtree.so
此外,opm不支持本地共享库(.so/.dll/.dylib):
opm目前只支持纯Lua库
查看文档。
您可能应该按照官方的安装说明-https://github.com/api7/lua-resty-radixtree#install
FWIW:你得到的错误在这里提出。

相关问题