luajit2: compiled-in default LUA_PATH lacks /usr/lib/lua - installing nginx-mod-lua makes nginx fail to start (resty.core not found)

Open
#30,980 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
lua
Domain
backend

Research direction

Start by reading lang/lua/luajit2/patches/010-lua-path.patch and compare its compiled-in Lua search paths with the stock lua 5.1 package defaults. Check how nginx-mod-lua-resty-core installs its Lua files under /usr/lib/lua/resty/ and whether the patch adds that directory to package.path. Done when the default search path can find those pure-Lua modules and the nginx Lua module starts without the reported resty.core error.

Written by the indexing model from the issue text.

Description

Maintainer: @javierbrk (luajit2 package)

Environment

  • ImmortalWrt SNAPSHOT r42541-2f97ee0c9f, x86_64, kernel 6.18.55 (luajit2 Makefiles are byte-identical between ImmortalWrt and openwrt.git feeds, so this applies upstream as well)
  • apk-tools 3.0.5
  • nginx-ssl 1.30.5-r1, nginx-mod-lua, nginx-mod-lua-resty-core, nginx-mod-lua-resty-lrucache, luci-nginx
  • luajit2 2.1.2026.07.31-r1 (PKG_SOURCE_VERSION 52f52587b37867ab19236eb6917001c2d6b662e7)

Steps to reproduce

  1. Install luci-nginx (works fine by itself).
  2. apk add nginx-mod-lua (pulls in luajit2 + resty-core packages).
  3. /etc/init.d/nginx restart -> nginx enters a procd crash loop, LuCI on 80/443 is down.

Log:

[alert] ... [lua] failed to load the 'resty.core' module ... no file './resty/core.lua'
    no file '/usr/share/luajit-2.1/resty/core.lua'
    no file '/usr/share/lua/resty/core.lua'   (listed twice)
    no file './resty/core.so'
    no file '/usr/lib/lua/resty/core.so' ...

Root cause

lang/lua/luajit2/patches/010-lua-path.patch rewrites luaconf.h:

-#define LUA_LROOT	"/usr/local"
-#define LUA_LUADIR	"/lua/5.1/"
+#define LUA_LROOT	"/usr"
+#define LUA_LUADIR	"/lua/"

Expanding the macros with these values yields the compiled-in defaults (verified against the shipped binary with strings /usr/lib/libluajit-5.1.so.2):

package.path  = ./?.lua;/usr/share/luajit-2.1/?.lua;/usr/share/lua/?.lua;/usr/share/lua/?/init.lua;/usr/share/lua/?.lua;/usr/share/lua/?/init.lua
package.cpath = ./?.so;/usr/lib/lua/?.so;/usr/lib/lua/?.so;/usr/lib/lua/loadall.so
  • /usr/share/lua does not exist on the target (no package installs there).
  • All Lua code on OpenWrt lives under /usr/lib/lua — including nginx-mod-lua-resty-core, which installs lib/resty/*.lua to /usr/lib/lua/resty/ (net/nginx/Makefile).
  • The patch adds /usr/lib/lua only to cpath (for .so), not to path (for .lua), so pure-Lua modules can never be found.

Contrast with the stock lua 5.1 package (openwrt.git package/utils/lua), whose default package.path includes both /usr/share/lua/?.lua and /usr/lib/lua/?.lua — luajit2 was never aligned with it.

Since lua-nginx-module loads resty.core automatically at http{} initialization (lua_load_resty_core defaults to on) and exits on failure, any nginx build with -mod-lua fails to start out of the box. nginx-util injects no lua_package_path either, so nothing compensates.

The same patch has shipped in the old luajit package since 2018 and was carried over verbatim when luajit2 was added (2023-09).

Suggested fix

Align the luajit2/luajit 010-lua-path.patch with the stock lua package by adding the libdir to the default path as well (OpenWrt installs arch-independent .lua under <prefix>/lib/lua, not <prefix>/share/lua), e.g. redefine LUA_PATH_DEFAULT to also include:

LUA_ROOT "/" LUA_MULTILIB "/lua/?.lua;" LUA_ROOT "/" LUA_MULTILIB "/lua/?/init.lua"

Alternatively, ship a compensating lua_package_path/lua_package_cpath conf snippet with nginx-mod-lua.

Workaround (confirmed working)

/etc/nginx/conf.d/99-lua-paths.conf:

lua_package_path '/usr/share/lua/?.lua;/usr/share/lua/?/init.lua;/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;;';
lua_package_cpath '/usr/lib/lua/?.so;;';

then /etc/init.d/nginx restart. LuCI comes back immediately.

Dominant language
Makefile
Stars
4.7k
Forks
4k
Avg merge
2d 2h
Merged PRs (30d)
251

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openwrt/packages

All issues in openwrt/packages

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.