使用 stream-lua-nginx-module 模块如何获取对方的ip地址?

221 views
Skip to first unread message

luke

unread,
Jan 5, 2018, 1:48:20 AM1/5/18
to openresty
Hi~

如题,如果在 content_by_lua_block 的lua代码中,如何获取 ngx.req.socket(true) 对应客户端的 tcp的 ip 地址和连接端口呢? 

直接用 lua 的 socket 库通过 cosocket获取的原生套接字获取麽?



tokers

unread,
Jan 5, 2018, 2:04:53 AM1/5/18
to openresty
Hi!

strem-lua-nginx-module 不是很了解,但是要拿客户端的 ip 和 port,
应该是 ngx.var.remote_addr 和 ngx.var.remote_port 就可以了,我看 stream 子系统里有这两个变量的。

luke

unread,
Jan 5, 2018, 2:17:58 AM1/5/18
to openresty
的确如此,感谢!

在 2018年1月5日星期五 UTC+8下午3:04:53,tokers写道:
Reply all
Reply to author
Forward
0 new messages