Closed tpimh closed 6 years ago
I usually create new lapis app in ~/mydir on Ubuntu 16.04 and start lapis server in that dir without problem. Nginx Openresty is installed at /usr/local/openresty/nginx/sbin/nginx.
The working directory of nginx must match where you're app.lua
file is, or you need to add that directory to the lua package path via the nginx configuration file.
The file named app.lua
is in the current working directory when I run lapis server
, so I think the line no file './app.lua'
refers to it. I tried symlinkng it to /usr/local/openresty/site/lualib/app.lua
and the result was similar.
When I copied app.lua
to /usr/local/openresty/site/lualib/app.lua
it worked! Why is it working for copied file, but not for symlink? Why doesn't it start in current directory? The ownership and permissions didn't change.
you can print the lua variable package.path
to see where lua files can be loaded. Generally there is a entry in there ./?.lua
when loads from the working directory of the process. By default this would be where you start the nginx process (via lapis server)
Closing this, feel free to leave a comment if you're still having an issue.
@leafo i have a similar error
2018/03/16 13:44:37 [error] 22069#22069: *2 lua entry thread aborted: runtime error: content_by_lua(nginx.conf.compiled:22):2: module 'lapis' not found: no field package.preload['lapis'] no file '/usr/local/openresty/site/lualib/lapis.ljbc' no file '/usr/local/openresty/site/lualib/lapis/init.ljbc' no file '/usr/local/openresty/lualib/lapis.ljbc' no file '/usr/local/openresty/lualib/lapis/init.ljbc' no file '/usr/local/openresty/site/lualib/lapis.lua' no file '/usr/local/openresty/site/lualib/lapis/init.lua' no file '/usr/local/openresty/lualib/lapis.lua' no file '/usr/local/openresty/lualib/lapis/init.lua' no file './lapis.lua' no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/lapis.lua' no file '/usr/local/share/lua/5.1/lapis.lua' no file '/usr/local/share/lua/5.1/lapis/init.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/lapis.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/lapis/init.lua' no file '/usr/local/openresty/site/lualib/lapis.so' no file '/usr/local/openresty/lualib/lapis.so' no file './lapis.so' no file '/usr/local/lib/lua/5.1/lapis.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/lapis.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: coroutine 0: [C]: in function 'require'
find / -name lapis.ljbc and result is nothing. how can i fix it?
@VuDn5 I'm not sure why you're searching for a ljbc
file, did you install lapis in a way that compiles it to luajit bytecode?
In any case, it's not finding lapis because your package.path
is not pointing to where you installed it. Did you install it with luarocks?
Assuming your luarocks executable is called luarocks
, you can see what the value of package.path
needs to be to find modules installed with it by running luarocks path --lr-path
You'll probably have to do the same thing for the cpath, needed by lapis' dependencies. (luarocks path --lr-cpath
)
You can set package.path
& co. using nginx configuration directive, or using the LUA_PATH
& LUA_CPATH
environment variables. Run luarocks path
to get the command to set the environment variables.
@leafo i install with luarock `[root@localhost ~]# luarocks install lapis Warning: falling back to curl - install luasec to get native HTTPS support Installing https://luarocks.org/lapis-1.6.0-1.src.rock... Using https://luarocks.org/lapis-1.6.0-1.src.rock... switching to 'build' mode Updating manifest for /usr/lib64/luarocks/rocks lapis 1.6.0-1 is now built and installed in /usr (license: MIT)
[root@localhost ~]# lapis server Error: file doesn't exist `nginx.conf'
@leafo where exactly the package.path should be pointed? ` [root@localhost lapis] # luarocks path --lr-path /root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua
[root@localhost lapis]# luarocks path export LUA_PATH='/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;./?.lua;/usr/lib64/lua/5.1/?.lua;/usr/lib64/lua/5.1/?/init.lua' export
LUA_CPATH='/root/.luarocks/lib64/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so;./?.so;/usr/lib64/lua/5.1/loadall.so'`
i just want to run example, but it doesn't simple... ^-^
@VuDn5
You can try:
eval `luarocks path`
lapis server
see luarocks path --help
@leafo ` luarocks path --help
LuaRocks 2.3.0, a module deployment system for Lua
NAME /bin/luarocks path - Return the currently configured package path.
SYNOPSIS
/bin/luarocks path
**and**
[root@localhost lapis] eval /bin/luarocks
LuaRocks 2.3.0, a module deployment system for Lua
NAME /bin/luarocks - LuaRocks main command-line interface
SYNOPSIS
/bin/luarocks [--from=
GENERAL OPTIONS These apply to all commands, as appropriate:
--server=<server> Fetch rocks/rockspecs from this server
(takes priority over config file)
--only-server=<server> Fetch rocks/rockspecs from this server only
(overrides any entries in the config file)
--only-sources=<url> Restrict downloads to paths matching the
given URL.
--tree=<tree> Which tree to operate on.
--local Use the tree in the user's home directory.
To enable it, see '/bin/luarocks help path'.
--verbose Display verbose output of commands executed.
--timeout=<seconds> Timeout on network operations, in seconds.
0 means no timeout (wait forever).
Default is 30.
VARIABLES Variables from the "variables" table of the configuration file can be overriden with VAR=VALUE assignments.
COMMANDS
build
Build/compile a rock.
config
Query information about the LuaRocks configuration.
doc
Show documentation for an installed rock.
download
Download a specific rock file from a rocks server.
help
Help on commands. Type '/bin/luarocks help
CONFIGURATION Lua version: 5.1 Configuration files: System: /etc/luarocks/config-5.1.lua (ok) User : /root/.luarocks/config-5.1.lua (not found)
Rocks trees in use:
/root/.luarocks ("user")
/usr ("system")
[root@localhost lapis] # lapis server no field package.preload['lapis'] no file '/usr/local/openresty/site/lualib/lapis.ljbc' no file '/usr/local/openresty/site/lualib/lapis/init.ljbc' no file '/usr/local/openresty/lualib/lapis.ljbc' no file '/usr/local/openresty/lualib/lapis/init.ljbc' no file '/usr/local/openresty/site/lualib/lapis.lua' no file '/usr/local/openresty/site/lualib/lapis/init.lua' no file '/usr/local/openresty/lualib/lapis.lua' no file '/usr/local/openresty/lualib/lapis/init.lua' no file './lapis.lua' no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/lapis.lua' no file '/usr/local/share/lua/5.1/lapis.lua' no file '/usr/local/share/lua/5.1/lapis/init.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/lapis.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/lapis/init.lua' no file '/usr/local/openresty/site/lualib/lapis.so' no file '/usr/local/openresty/lualib/lapis.so' no file './lapis.so' no file '/usr/local/lib/lua/5.1/lapis.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/lapis.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: coroutine 0: [C]: in function 'require' ` it nothing change. thanks for your help
It's not clear that you ran the commands as I wrote them.
luarocks path
prints out shell variable exports, putting them in using eval and ` will export those variables to the current shell session, setting the LUA_PATH and LUA_CPATH. Afterwards, when you start the lapis server it should be able to read them. If it's still not picking it up you might need to add the ENV directives to nginx configuration, since it's not inheriting environment variables from the shell you're in.
I mentioned luarocks path --help
since it teaches you about how the path command works.
i don't know setting like what? i run luarocks install lapis in /root directives , you want me change LUA_PATH and LUA_CPATH how? sorry about my questions that not smart! @leafo
I still get an error
nginx: [alert] lua_code_cache is off; this will hurt performance in /Users/jinglian/Desktop/yel/nginx.conf.compiled:17 2022/04/09 21:29:12 [notice] 90669#33012369: using the "kqueue" event method 2022/04/09 21:29:12 [warn] 90669#33012369: 1024 worker_connections exceed open file resource limit: 256 2022/04/09 21:29:12 [notice] 90669#33012369: openresty/1.19.9.1 2022/04/09 21:29:12 [notice] 90669#33012369: built by clang 12.0.0 (clang-1200.0.32.29) 2022/04/09 21:29:12 [notice] 90669#33012369: OS: Darwin 19.6.0 2022/04/09 21:29:12 [notice] 90669#33012369: hw.ncpu: 8 2022/04/09 21:29:12 [notice] 90669#33012369: net.inet.tcp.sendspace: 131072 2022/04/09 21:29:12 [notice] 90669#33012369: kern.ipc.somaxconn: 128 2022/04/09 21:29:12 [notice] 90669#33012369: getrlimit(RLIMIT_NOFILE): 256:9223372036854775807 2022/04/09 21:29:12 [notice] 90669#33012369: start worker processes 2022/04/09 21:29:12 [notice] 90669#33012369: start worker process 90671 2022/04/09 21:29:15 [error] 90671#33012376: *1 lua entry thread aborted: runtime error: error loading module 'lpeg' from file '/usr/local/lib/lua/5.4/lpeg.so': dlopen(/usr/local/lib/lua/5.4/lpeg.so, 6): Symbol not found: _luaL_checkversion_ Referenced from: /usr/local/lib/lua/5.4/lpeg.so Expected in: flat namespace in /usr/local/lib/lua/5.4/lpeg.so stack traceback: coroutine 0: [C]: in function 'require' content_by_lua(nginx.conf.compiled:27):3: in main chunk, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"
I installed openresty and lapis on Alpine Linux, and it creates new project and starts server without errors:
But if I try to access the server, it can not find
app.lua
(the file is actually in my current directory):What may be causing this?