Skip to content

Latest commit

 

History

History
125 lines (90 loc) · 4.75 KB

记录一次编译nginx安装lua模块后运行nginx报错解决.md

File metadata and controls

125 lines (90 loc) · 4.75 KB
title category tags updatedAt date
记录一次编译nginx安装lua模块后运行nginx报错解决
vanblog配置
nginx,linux
2024-02-19 14:36:19 UTC
2024-02-14 13:11:31 UTC

之前手动编译安装了nginx最新版,因为当时忘了给nginx添加lua模块。就重新下载了lua模块源码重新编译,编译时提示./configure: error: unsupported LuaJIT version; ngx_http_lua_module requires LuaJIT 2.x.,添加完环境变量后正常编译了,编译完后运行nginx报错。看错误提示,应该主要是module 'thread.exdata' not foundmodule 'resty.core' not found这俩问题。 折腾几个小时才搞定。特地记录下。

2024-2-18更新:

如果使用宝塔的一键安装脚本安装1.25.3nginx也出现这个问题,可以尝试在nginx配置文件中http{} 这一段加入lua_package_path "/www/server/nginx/lib/lua/?.lua;";

运行错误提示:

root@VM-0-4-debian:/www/server/nginxmodel/lua-resty-core-0.1.28# /etc/init.d/nginx  start
Starting nginx... nginx: [error] failed to run the Lua code for coroutine_api: 2: coroutine_api:2: module 'thread.exdata' not found:
	no field package.preload['thread.exdata']
	no file '/usr/local/Lua_core/lib/lua/thread/exdata.lua'
	no file './thread/exdata.so'
	no file '/usr/local/lib/lua/5.1/thread/exdata.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './thread.so'
	no file '/usr/local/lib/lua/5.1/thread.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
	no field package.preload['resty.core']
	no file '/usr/local/Lua_core/lib/lua/resty/core.lua'
	no file './resty/core.so'
	no file '/usr/local/lib/lua/5.1/resty/core.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './resty.so'
	no file '/usr/local/lib/lua/5.1/resty.so'
	no file '/usr/local/lib/lua/5.1/loadall.so') in /www/server/nginx/conf/nginx.conf:98
 failed

解决module 'resty.core' not found

我在编译nginx时用的lua-nginx-module版本是0.10.26,低版本的模块(<0.10.16)可以使用lua_load_resty_core off;这个配置解决问题。高版本的模块中不支持这行配置命令,要解决这个问题,就要手动安装lua-resty-lrucachelua-resty-core

下载lua-resty-lrucachelua-resty-core这两个模块源代码,使用make install命令安装这两个模块。

执行命令:

wget https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.13.zip
unzip v0.13.zip
cd lua-resty-lrucache-0.13/
make install PREFIX=/usr/local/lua_core

wget https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.28.zip
unzip v0.1.28.zip
cd lua-resty-core-0.1.28/
make install PREFIX=/usr/local/lua_core

找到nginx配置文件,在http{}中加上一条lua_package_path '/usr/local/lua_core/lib/lua/?.lua;';即可。

make install PREFIX=/usr/local/lua_core就是把模块安装在/usr/local/lua_core目录中

参考:https://blog.51cto.com/u_15064643/4273810

再次执行/etc/init.d/nginx start测试,不报module 'resty.core' not found错误了,这个问题解决了。

root@VM-0-4-debian:/www/server/nginxmodel/lua-resty-core-0.1.28# /etc/init.d/nginx  start
Starting nginx... nginx: [error] failed to run the Lua code for coroutine_api: 2: coroutine_api:2: module 'thread.exdata' not found:
	no field package.preload['thread.exdata']
	no file '/usr/local/lua_core/lib/lua/thread/exdata.lua'
	no file './thread/exdata.so'
	no file '/usr/local/lib/lua/5.1/thread/exdata.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './thread.so'
	no file '/usr/local/lib/lua/5.1/thread.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'

解决module 'thread.exdata' not found

搞完module 'resty.core' not found的问题还有module 'thread.exdata' not found的问题。

先卸载之前安装的luajit,再安装openresty优化的luajit

cd /www/server/nginxmodel/LuaJIT
make uninstall

之前是用源代码编译安装的,卸载也是进源代码目录直接执行make uninstall

下载openresty优化后的luajit程序源代码,然后编译安装luajit

执行:

wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20231117.zip
unzip v2.1-20231117.zip
cd /www/server/nginxmodel/luajit2-2.1-20231117
make
make install

使用luajit -v测试,输出版本号,安装成功。

root@VM-0-4-debian:/opt/vanblog# luajit -v
LuaJIT 2.1.1700206165 -- Copyright (C) 2005-2023 Mike Pall. https://luajit.org

参考:https://blog.csdn.net/wzr54321/article/details/127702437

成功解决这俩问题,nginx正常启动无报错,大功告成。。。