nginx - openresty无法使用require
问题描述
不使·access_check.lua的时候,程序运行正常,使用就会出现错误。环境使用了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)
错误日志如下:
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'
项目目录结构如下:

问题解答
回答1:已经解决了这个问题
相关文章:
1. node.js - 我是一个做前端的,求教如何学习vue,node等js引擎?2. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?3. docker api 开发的端口怎么获取?4. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?5. 如何解决docker宿主机无法访问容器中的服务?6. 老师,flex-shrink: 1; 按视频操作,不会自动缩放7. java - 为什么第一个线程已经释放了锁,第二个线程却不行?8. sublime-text - sublime text 3中编译python(sublimeREPL),如何仅运行单行/选定部分9. 前端 - 类到底该如何去命名 .newsList 这种的命名难道真的不是过度语义化吗?~10. PHP中的$this代表当前的类还是方法?

网公网安备