在文件中
package.path = ‘/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;‘ package.cpath = ‘/usr/local/lib/lua/5.1/?.so;‘ 执行local mysql = require "mysql" --正确local mysql = require "resty.mysql" --报错 去掉
package.path = ‘/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;‘ package.cpath = ‘/usr/local/lib/lua/5.1/?.so;‘
local mysql = require "mysql" --报错local mysql = require "resty.mysql" --正确
package.path 的默认路径指向哪的呢?
去掉 package.path,在页面中 随便引用一个不存在的模块 比如 require ‘aa‘
查看nginx错误日志返回
no field package.preload[‘aa‘] no file ‘/usr/local/openresty/lualib/aa.lua‘ no file ‘/usr/local/openresty/lualib/aa/init.lua‘ no file ‘./aa.lua‘ no file ‘/usr/local/openresty/luajit/share/luajit-2.1.0-alpha/aa.lua‘ no file ‘/usr/local/share/lua/5.1/aa.lua‘ no file ‘/usr/local/share/lua/5.1/aa/init.lua‘ no file ‘/usr/local/openresty/luajit/share/lua/5.1/aa.lua‘ no file ‘/usr/local/openresty/luajit/share/lua/5.1/aa/init.lua‘ no file ‘/usr/local/openresty/lualib/aa.so‘ no file ‘./aa.so‘ no file ‘/usr/local/lib/lua/5.1/aa.so‘ no file ‘/usr/local/openresty/luajit/lib/lua/5.1/aa.so‘ no file ‘/usr/local/lib/lua/5.1/loadall.so‘
发现 /usr/local/openresty/lualib/aa.lua 难道默认的路径是 /usr/local/openresty/lualib 于是在页面中加入
package.path = ‘/usr/local/share/lua/5.1/?.lua;/usr/local/openresty/lualib/resty/?.lua;/usr/local/openresty/lualib/?.lua;‘ package.cpath = ‘/usr/local/lib/lua/5.1/?.so;‘
执行正确
新手~~ 勿怪
时间: 2024-11-03 09:25:16