luasocket installed by luarocks:
This works fine:
$ sudo luarocks install luasocket
$ lua
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
require "socket"
This works fine:
$ cat test.lua
require "socket"
$ lua test.lua
but This not works:
nginx.conf:
location /lua {
default_type 'text/plain';
content_by_lua_file test.lua;
}
$ tail nginx/error.log
2021/09/19 00:07:35 [error] 24355#1528448: *29 lua entry thread aborted: runtime error: /Users/xxx/lua/test.lua:1: module 'socket' not found:
no field package.preload['socket']
no file '/usr/local/Cellar/openresty/1.15.8.1/site/lualib/socket.ljbc'
no file '/usr/local/Cellar/openresty/1.15.8.1/site/lualib/socket/init.ljbc'
no file '/usr/local/Cellar/openresty/1.15.8.1/lualib/socket.ljbc'
no file '/usr/local/Cellar/openresty/1.15.8.1/lualib/socket/init.ljbc'
no file '/usr/local/Cellar/openresty/1.15.8.1/site/lualib/socket.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/site/lualib/socket/init.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/lualib/socket.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/lualib/socket/init.lua'
no file './socket.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/luajit/share/luajit-2.1.0-beta3/socket.lua'
no file '/usr/local/share/lua/5.1/socket.lua'
no file '/usr/local/share/lua/5.1/socket/init.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/luajit/share/lua/5.1/socket.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/luajit/share/lua/5.1/socket/init.lua'
no file '/usr/local/Cellar/openresty/1.15.8.1/site/lualib/socket.so'
no file '/usr/local/Cellar/openresty/1.15.8.1/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/usr/local/Cellar/openresty/1.15.8.1/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
coroutine 0:
[C]: in function 'require'
/Users/xxx/lua/test.lua:1: in main chunk, client: 127.0.0.1, server: _, request: "GET /lua HTTP/1.1", host: "127.0.0.1"
`$ luarocks list
Rocks installed for Lua 5.4
luasocket
3.0rc1-2 (installed) - /usr/local/lib/luarocks/rocks-5.4`