I am new here,我想通过nginx stream 和 lua实现一个tcp服务端,收发数据先在content_by_lua_block中简单做了一些逻辑。但是客户端收到请求后,nginx自动发送tcp fin指令将连接关闭了,导致客户端无法复用连接。
nginx stream配置
```nginx
stream {
lua_socket_keepalive_timeout 10s;
server {
listen 12400 so_keepalive=65s;
proxy_timeout 10m;
#proxy_requests 100;
#lua_socket_keepalive_timeout 60s;
content_by_lua_block {
local sock = ngx.req.socket(true)
local s_got = sock:receive()
ngx.print('server got:'..s_got)
}
}
}
```
用telnet模拟发送请求,收到response之后提示连接被远程断开
```console
➜ ~ telnet 11.122.171.152 12400
Trying 11.122.171.152...
Connected to 11.122.171.152.
Escape character is '^]'.
hello
server got:helloConnection closed by foreign host.
```
抓包看了下,nginx发送了tcp fin指令主动断开了连接。
223 15.265932 11.122.171.152 30.197.132.178 TCP 60 12400 → 56478 [FIN, ACK] Seq=14 Ack=5 Win=42496 Len=0
请问在stream中没有upstream server的情况下实现keepalive。