nginx - openresty無(wú)法使用require
問(wèn)題描述
不使·access_check.lua的時(shí)候,程序運(yùn)行正常,使用就會(huì)出現(xiàn)錯(cuò)誤。環(huán)境使用了docker的openresty/openresty官方鏡像。
nginx.conf配置如下:
worker_processes 1;error_log logs/error.log;events { worker_connections 1024;}http { lua_package_path 'lua/?.lua;app/?.lua'; lua_code_cache off; server {listen 6699;charset utf-8;#lua_need_request_body on;location / { default_type text/html; content_by_lua_block {ngx.say('hello fatrbaby') }}location ~ ^/api/([-_a-zA-Z0-9/]+) { access_by_lua_file lua/access_check.lua; content_by_lua_file lua/$1.lua;} }}
access_check.lua代碼如下:
local validator = require('lib.validator')local args = ngx.req.get_uri_args()if not validator.is_number(args.a, args.b) then ngx.exit(ngx.HTTP_BAD_REQUEST) returnendngx.print(package.path)
錯(cuò)誤日志如下:
2017/04/26 09:11:34 [error] 216#216: *1 lua entry thread aborted: runtime error: /usr/local/var/learn/lua/access_check.lua:1: module ’lib.validator’ not found: no field package.preload[’lib.validator’] no file ’lua/lib/validator.lua’ no file ’app/lib/validator.lua’ no file ’/usr/local/openresty/site/lualib/lib/validator.so’ no file ’/usr/local/openresty/lualib/lib/validator.so’ no file ’./lib/validator.so’ no file ’/usr/local/lib/lua/5.1/lib/validator.so’ no file ’/usr/local/openresty/luajit/lib/lua/5.1/lib/validator.so’ no file ’/usr/local/lib/lua/5.1/loadall.so’ no file ’/usr/local/openresty/site/lualib/lib.so’ no file ’/usr/local/openresty/lualib/lib.so’ no file ’./lib.so’ no file ’/usr/local/lib/lua/5.1/lib.so’ no file ’/usr/local/openresty/luajit/lib/lua/5.1/lib.so’ no file ’/usr/local/lib/lua/5.1/loadall.so’stack traceback:coroutine 0: [C]: in function ’require’ /usr/local/var/learn/lua/access_check.lua:1: in function </usr/local/var/learn/lua/access_check.lua:1>, client: 172.17.0.1, server: , request: 'GET /api/add?a=1&b=6 HTTP/1.1', host: 'localhost:6699'
項(xiàng)目目錄結(jié)構(gòu)如下:
問(wèn)題解答
回答1:已經(jīng)解決了這個(gè)問(wèn)題
相關(guān)文章:
1. python - pyspider的分布式運(yùn)行成功,2臺(tái)slave跑,但是時(shí)間并沒有縮短問(wèn)題?2. 致命錯(cuò)誤: Class ’appfacadeTest’ not found3. dockerfile - 為什么docker容器啟動(dòng)不了?4. angular.js - 用requireJS模塊angularjs代碼時(shí)遇到一些問(wèn)題5. android - Apk 中找不到r類文件6. npm install -g browser-sync這個(gè)之后出錯(cuò) 還有人嗎 我都感覺沒人回答問(wèn)題了7. python - 數(shù)據(jù)無(wú)法插入到mysql表里8. javascript - 小程序跳轉(zhuǎn)失敗?9. javascript - 求正則表達(dá)式的寫法10. java - Oracle如何獲取去重結(jié)果集中某一條數(shù)據(jù)的下一條數(shù)據(jù)
