使用lua-resty-repl 调试openresty
lua-resty-repl 是一个方便的openresty 包,我们可以用来方便的调试openresty
以下是一个基于容器运行的一个试用
环境准备
- dockerfile
主要是安装模块以及一个supervisord(方便运行的,使用此接管1号进程)
FROM openresty/openresty:alpine-fat
RUN /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories
RUN apk update && apk add git
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord
RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-repl
ENTRYPOINT [ "/usr/local/bin/supervisord" ]
- docker-compose 文件
version: "3"
services:
api:
build: ./
image: dalongrong/openresty:lua-resty-repl
volumes:
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
- "./supervisor.conf:/etc/supervisor.conf"
ports:
- "80:80"
- "9001:9001"
- supervisor 配置
可以不用
[inet_http_server]
port = :9001
- nginx 配置
nginx.conf
master_process off;
worker_processes 1;
error_log stderr notice;
daemon off;
events {
worker_connections 1024;
}
http {
server {
listen 80;
lua_code_cache off;
include mime.types;
default_type application/octet-stream;
gzip on;
resolver 127.0.0.11 ipv6=off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location / {
content_by_lua_block {
require('resty.repl').start()
}
}
}
}
试用
- 构建镜像
docker-compose build
- 启动
docker-compose up -d
- 启动openresty
进入容器
docker-compose exec api sh
openresty -c /usr/local/openresty/nginx/conf/nginx.conf
- 发送请求
http://localhost/?username=dalong&age=333
- 效果
- 执行调试命令
ngx.req.get_uri_args()
效果
说明
lua-resty-repl 是一个不错的openresty 调试工具,可以帮助我们调试一些问题,相比使用ngx.say 以及ngx.log 方便了好了很多
参考资料
https://github.com/saks/lua-resty-repl
https://github.com/rongfengliang/lua-resty-repl-learning
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-06-10 circus web console 依赖tornado>3.2 无法访问的bug
2019-06-10 circus 做为批处理的守护进程
2019-06-10 circus 架构
2019-06-10 sphinx doc 文档生成脚手架工具
2019-06-10 circus docker image web 运行异常问题的解决
2019-06-10 circus 进程以及socket 管理工具&&docker运行
2019-06-10 a list of frequently asked questions about Circus