在文件中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 = '/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 的默認路徑指向哪的呢?nginx
去掉 package.path,在頁面中 隨便引用一個不存在的模塊 好比 require 'aa'sql
查看nginx錯誤日誌返回ui
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 因而在頁面中加入lua
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;'
ngx.say(package.path)spa
執行正確rest
新手~~ 勿怪日誌