openresty / openresty/lua-nginx-module
LUA_PATH must contain /usr/share/lua and /usr/lib/x86_64-linux-gnu/lua/
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
I have a script that require("socket.unix") and the library is installed in Ubuntu with apt install lua-socket.
But the OpenResty can't resolve the library:
no file '/usr/local/lib/lua/5.1/socket.so'
This is because it's not it the /usr/local/lib/lua/ but in /usr/lib/x86_64-linux-gnu/lua/.
But this will work if a library was installed with luarocks because it's indeed uses the /usr/local/lib/lua/.
I tried to solve this by adding lua_package_path and lua_package_cpath like this:
# By default Lua libraies are looked in the /usr/local/share/lua/ and /usr/local/lib/lua/ but must look into /usr/share/lua/ and /usr/lib/x86_64-linux-gnu/lua/
# set search paths for pure Lua external libraries (';;' is the default path):
lua_package_path '/usr/share/lua/5.1/?.lua;;';
# set search paths for Lua external libraries written in C (can also use ';;'):
lua_package_cpath '/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;;';
This partially solved a problem but failed with another error attempt to call method 'get_certificate' (a nil value).
This is probably because packages has own directories that also needs to be added recursively.
I had to add them manually like this:
# By default Lua libraies are looked in the /usr/local/share/lua/ and /usr/local/lib/lua/ but must look into /usr/share/lua/ and /usr/lib/x86_64-linux-gnu/lua/
# set search paths for pure Lua external libraries (';;' is the default path):
lua_package_path '/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/socket/?.lua;/usr/share/lua/5.1/ssl/?.lua;;';
# set search paths for Lua external libraries written in C (can also use ';;'):
lua_package_cpath '/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/socket/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/mime/?.so;;';
This again didn't worked, don't know why. Anyway this solution would be fragile. Once a new library with own folder installed it also should be manually added to the path.
The only solution that worked was to create symlinks:
ln -s /usr/share/lua /usr/local/share/
ln -s /usr/lib/x86_64-linux-gnu/lua/ /usr/local/lib/
This is not something that I like but solves the problem for now.
I wish to hear how to solve this correctly. At least please add more examples to the lua_package_path and lua_package_cpath.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by reproducing the Ubuntu lua-socket lookup failure with the shown lua_package_path and lua_package_cpath settings, then inspect how the module resolves Lua libraries. Done means establishing a supported path configuration or documenting the correct behavior and examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100