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

Aperta
#30,980 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
lua
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Makefile
Stelle
4.7k
Fork
4k
Merge medio
2g 2h
PR unite (30g)
251

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openwrt/packages

Tutte le issue di openwrt/packages

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.