老师好,
我是按照您给我的网址配置的,websocket连接时好时坏(连不上的概率大概是20%)
我的nginx配置如下:
location /api/socket.io {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://socketio_nodes/socket.io;
error_log /home/xkool/volume/log/chenyuan.log debug;
}
然后我加了debug日志,发现####连的上####的情况下,debug日志如下:
49 2019/02/26 15:36:25 [debug] 16712#0: *887 writev: 661 of 661
50 2019/02/26 15:36:25 [debug] 16712#0: *887 chain writer out: 0000000000000000
51 2019/02/26 15:36:25 [debug] 16712#0: *887 event timer del: 19: 1551166645770
52 2019/02/26 15:36:25 [debug] 16712#0: *887 event timer add: 19: 60000:1551166645770
53 2019/02/26 15:36:25 [debug] 16712#0: *887 http upstream request: "/api/socket.io/?EIO=3&transport=polling&t=MaekxjO &sid=366b9fc32e2a42e595b703f4d02075bd"
54 2019/02/26 15:36:25 [debug] 16712#0: *887 http upstream process header
55 2019/02/26 15:36:25 [debug] 16712#0: *887 malloc: 00000000026B8450:4096
####连不上####的情况,日志如下:
49 2019/02/26 15:36:25 [debug] 16715#0: *893 writev: 661 of 661
50 2019/02/26 15:36:25 [debug] 16715#0: *893 chain writer out: 0000000000000000
51 2019/02/26 15:36:25 [debug] 16715#0: *893 event timer del: 13: 1551166645863
52 2019/02/26 15:36:25 [debug] 16715#0: *893 event timer add: 13: 60000:1551166645863
53 2019/02/26 15:37:25 [debug] 16715#0: *893 http upstream request: "/api/socket.io/?EIO=3&transport=polling&t=Maekxkt &sid=366b9fc32e2a42e595b703f4d02075bd"
54 2019/02/26 15:37:25 [debug] 16715#0: *893 http upstream process header
55 2019/02/26 15:37:25 [debug] 16715#0: *893 malloc: 00000000026819B0:4096
56 2019/02/26 15:37:25 [debug] 16715#0: *893 recv: eof:0, avail:1
57 2019/02/26 15:37:25 [debug] 16715#0: *893 recv: fd:13 137 of 4096
58 2019/02/26 15:37:25 [debug] 16715#0: *893 http proxy status 400 "400 BAD REQUEST"
########分界线##########
可以看出#连不上#的情况下第52行、53行之间有个60秒的间隔,也就是说nginx等了60秒才转发我的请求到上游(可是这个时候上游的socket已经关了),抓包也验证了如上行为。请问什么情况下会出现这个呢?我没有设置任何limit
展开
作者回复: 看日志,不像是连接不上,而是读取响应超时。最后即使读取响应未超时,返回的也是400。是不是你的请求格式不正确,导致websocket服务器拒绝返回?readtime_out定时器超时?