如何在nginx配置文件中调试lua代码?
2014-10-4 3:50:49
收藏:0
阅读:128
评论:3
我想在我的 Lua 代码中插入日志点(使用 io.write),这些 Lua 代码是在 nginx 配置中使用 HttpLuaModule 进行的。 该怎么做? 访问日志和错误日志并没有显示它们。
点赞
用户1442917
另一个在nginx中进行Lua调试的选择(除了“打印”)是使用支持远程调试的Lua IDE。我在这里发布了如何使用ZeroBrane Studio IDE进行此操作的说明。一旦设置完成,您将获得大多数您期望的调试功能,如逐步执行、断点、变量检查、堆栈跟踪以及一个运行Lua命令的控制台,可以在远程环境下运行。
2015-07-11 05:30:04
用户590307
另一个用于 OpenResty 的故障排查工具是lua-resty-console,它允许您检查 Lua 变量、导入模块、调用函数等。您要做的就是使用luarocks安装它,并在您的nginx.conf中插入几行代码。启动客户端,您就可以使用它了。
[9] ngx(content)> ngx.config.prefix()
=> /workspace/lua-resty-console/
[10] ngx(content)> ngx.config.ngx_lua_version
=> 10011
[11] ngx(content)> ngx.config.nginx_configure()
=> --prefix=/usr/local/Cellar/openresty/1.13.6.1/nginx --with-cc-opt='-O2 -I/usr/local/include -I/usr/local/opt/pcre/include -I/usr/local/opt/openresty-openssl/include' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 ...
[12] ngx(content)> ngx.sha →→
ngx.sha1_bin() ngx.shared.
[12] ngx(content)> ngx.shared. →→
ngx.shared.mycache. ngx.shared.metrics.
[12] ngx(content)> c = ngx.shared.mycache
=> nil
[13] ngx(content)> c
=> { <userdata 1>,
<metatable> = <1>{
__index = <table 1>,
add = <function 1>,
delete = <function 2>,
flush_all = <function 3>,
flush_expired = <function 4>,
get = <function 5>,
get_keys = <function 6>,
get_stale = <function 7>,
incr = <function 8>,
llen = <function 9>,
lpop = <function 10>,
lpush = <function 11>,
replace = <function 12>,
rpop = <function 13>,
rpush = <function 14>,
safe_add = <function 15>,
safe_set = <function 16>,
set = <function 17>
}
}
[14] ngx(content)> c:set('a', 1)
=> true
[15] ngx(content)> c:get('a')
=> 1
[16] ngx(content)> c:get_keys()
=> { "a" }
2019-01-28 03:30:56
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
在使用 nginx 时,应该使用 ngx.log。例如:
ngx.log(ngx.STDERR, 'your message here')有一个可行的示例,请参见http://linuxfiddle.net/f/77630edc-b851-487c-b2c8-aa6c9b858ebb
有关文档,请参见http://wiki.nginx.org/HttpLuaModule#ngx.log。