【发布时间】:2020-07-22 09:03:31
【问题描述】:
我的后端在开发过程中完美地处理了 API 请求和 Socket.IO 请求。在生产中,我的后端仍然可以完美地处理 API 请求,但不响应 Socket.IO 请求。
看来 Socket.IO 客户端连接到后端没有问题,因为它获得了 pong 和 undefined 数据和以下响应:
HTTP/1.1 101 Switching Protocols
Server: nginx/1.17.6
Date: Wed, 22 Jul 2020 08:50:51 GMT
Connection: upgrade
Upgrade: websocket
Sec-WebSocket-Accept: +XXXXxxXxxX/xxxxXXXxxxxx/Xx=
Sec-WebSocket-Extensions: permessage-deflate
Strict-Transport-Security: max-age=31536000
更新 1
我尝试使用Echo Test 连接到后端并成功连接。
更新 2
这里是 Socket.IO 客户端日志:
socket.io-client:url parse https://staging.backend.xxx.us/dashboard
socket.io-client new io instance for https://staging.backend.xxx.us/dashboard
socket.io-client:socket emitting packet with ack id 0
socket.io-client:socket emitting packet with ack id 1
socket.io-client:socket emitting packet with ack id 2
socket.io-client:manager readyState closed
socket.io-client:manager opening https://staging.backend.xxx.us/dashboard
engine.io-client:socket creating transport "websocket"
engine.io-client:socket setting transport websocket
socket.io-client:manager connect attempt will timeout after 20000
engine.io-client:socket socket receive: type "open", data "{"sid":"fk3DbI3H-0qXRZEAAAAU","upgrades":[],"pingInterval":25000,"pingTimeout":5000}"
engine.io-client:socket socket open
socket.io-client:manager open
socket.io-client:manager cleanup
socket.io-client:socket transport is open - connecting
socket.io-client:manager writing packet {"type":0,"nsp":"/dashboard"}
socket.io-parser encoding packet {"type":0,"nsp":"/dashboard"}
socket.io-parser encoded {"type":0,"nsp":"/dashboard"} as 0/dashboard,
engine.io-client:socket flushing 1 packets in socket
engine.io-client:socket socket receive: type "message", data "0"
socket.io-parser decoded 0 as {"type":0,"nsp":"/"}
engine.io-client:socket socket receive: type "message", data "4/dashboard,"invalid signature""
socket.io-parser decoded 4/dashboard,"invalid signature" as {"type":4,"nsp":"/dashboard","data":"invalid signature"}
engine.io-client:socket writing ping packet - expecting pong within 5000ms
engine.io-client:socket flushing 1 packets in socket
engine.io-client:socket socket receive: type "pong", data "undefined"
engine.io-client:socket socket close with reason: "transport close"
socket.io-client:manager onclose
socket.io-client:manager cleanup
socket.io-client:socket close (transport close)
socket.io-client:manager will wait 690ms before reconnect attempt
socket.io-client:manager attempting reconnect
更新 3
我通过将 Socket.IO 路径更改为 / 进行了测试,但没有成功,我得到了相同的结果。
更新 4
我将 Socket.IO 客户端传输更改为 polling 进行了测试,但没有成功,我得到了相同的结果。
【问题讨论】: