I'm new to OpenResty, and I was trying to use the lua-resty-radixtree library, and I am running into an error:
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>
Here is the Lua code:
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)
And the Nginx configuration:
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
content_by_lua_file lua/hello.lua;
}
}
}
I had installed the libraries through OPM by running:
sudo opm get xiangnanscu/lua-resty-radixtree
sudo opm get xiangnanscu/lua-resty-expr
sudo opm get xiangnanscu/lua-resty-ipmatcher
Looking into the issue, I found that OpenResty is under this path /usr/bin/openresty
while the Lua library is searching for the .so file in the /usr/local/openresty
folder as shown in the error.
I tried setting this in the nginx.conf
file but it did not change anything:
lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";
Any idea what the issue is and how to fix it? Thanks in advance!