You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过resty CLI运行含ngx.process的OpenResty配置,无需启动Nginx?

用resty CLI运行ngx.process相关代码(无需启动OpenResty服务)

你提供的代码依赖OpenResty的多进程架构(master、worker、特权代理进程),而resty CLI是单进程运行模式,仅模拟content阶段的执行环境,init_by_lua和init_worker_by_lua阶段不会被触发,且ngx.process模块的部分API(如enable_privileged_agent、区分多进程类型的type())在单进程环境下无法正常工作。

要在resty CLI下快速测试代码,需做如下调整:

调整后的代码

local process = require "ngx.process"

-- resty CLI仅支持content阶段逻辑,直接输出进程信息
ngx.say("process type: ", process.type())
ngx.say("master process pid: ", process.get_master_pid() or "当前为resty CLI单进程模式,无master进程")

运行方式

直接执行命令:

resty your-adjusted-script.lua

修改代码后重新运行该命令即可,无需重启或重载OpenResty服务。

注意事项

  • resty CLI的单进程环境中,process.type()会固定返回"single",无法测试master、worker、特权代理进程的区分逻辑
  • 若需验证多进程相关功能(如启用特权代理进程),仍需通过完整的OpenResty配置文件启动服务进行测试

内容的提问来源于stack exchange,提问作者Zachary

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 06:30:34