大家好:
根据 init_worker_by_lua 的描述,我认为,在这个 directive 中,可以实现一个 worker 中共享的全局变量。
但下面这段代码中, 每个 client 进行连接时, 都会打印 conns is nil。
-- nginx conf
init_worker_by_lua_file tests/init.lua;
-- init.lua
if not conns then
ngx.log(ngx.ERR, 'conns is nil')
conns = {}
end
在这里,我并不想使用 ngx.shared.DICT,而使用 resty.lrucache 也有同样的问题。
2015/01/14 10:26:32 [error] 75239#0: *78 init_by_lua_file error: /Volumes/HD1/works/hhl/dtserver/tests/init.lua:18: no request
stack traceback:
[C]: in function 'at'
/Volumes/HD1/works/hhl/dtserver/tests/init.lua:18: in main chunk, client: 127.0.0.1, server: localhost, request: "GET /test HTTP/1.1", host: "127.0.0.1:1091"
但邮件列表中有人是可以正常工作的:
我怀疑是否由于:
When the master process is disabled, this hook will just run afterinit_by_lua*.
但我的配置文件中, master_process 是 on 的状态。
请问应该如何理解?