2016-05-06 11 views
2

Socket.ioを使用してJavascript(React)アプリケーションでWebSocketを設定しようとしています。WebSocketの接続に失敗しました:reserved1 = 0、reserved2 = 1、reserved3 = 1

Socket.ioクライアント(v1.4.5)からpollingトランスポートを使用すると、すべて正常に動作します。 しかし、私は実際と安全なWebSocketを(wss://プロトコル)を使用したいと思います...

私のサーバーは、私の仮想ホストのプロキシとしてのDebian 7を実行してnginxのv1.2.1デベロッパーである、と私のNode.jsアプリ(使用してソケット.io v1.4.5)。

私のドメイン名(api.tribeez.net)は(SSL、すなわちwss://上を含む)がjust announcedフルWebSocketをsupportCloudFlareを経由して設定されています。

Chrome(v50.0)でアプリを起動すると、Chromeのネットワークパネル(状態pending)にWebSocket接続が表示されます。 しかし、1分後、WebSocketの接続を切断(ステータス101 Switching Protocols)とコンソールが私にスローが、これは私が何を得るWebSocket connection to 'wss://api.tribeez.net/socket.io/?EIO=3&transport=websocket&t=LI3t1dh' failed: One or more reserved bits are on: reserved1 = 0, reserved2 = 1, reserved3 = 1

socket.ioデバッグをオンに紛らわしいです:

Fri, 06 May 2016 02:23:37 GMT socket.io:server incoming connection with id L43EOXmwsqkgCMVJAAAD 
Fri, 06 May 2016 02:23:37 GMT socket.io:client connecting to namespace/
Fri, 06 May 2016 02:23:37 GMT socket.io:namespace adding socket to nsp/
Fri, 06 May 2016 02:23:37 GMT socket.io:socket socket connected - writing packet 
Fri, 06 May 2016 02:23:37 GMT socket.io:socket joining room /#L43EOXmwsqkgCMVJAAAD 
Fri, 06 May 2016 02:23:37 GMT socket.io:client writing packet {"type":0,"nsp":"/"} 
Fri, 06 May 2016 02:23:37 GMT socket.io-parser encoding packet {"type":0,"nsp":"/"} 
Fri, 06 May 2016 02:23:37 GMT socket.io-parser encoded {"type":0,"nsp":"/"} as 0 
Transport=websocket, query=/socket.io/?EIO=3&transport=websocket&t=LI3t1dh 
Fri, 06 May 2016 02:23:37 GMT socket.io:socket joined room /#L43EOXmwsqkgCMVJAAAD 
Fri, 06 May 2016 02:23:37 GMT socket.io:socket joining room tribe#1 
Fri, 06 May 2016 02:23:37 GMT socket.io:socket joined room tribe#1 
Fri, 06 May 2016 02:24:37 GMT socket.io:client client close with reason transport close 
Fri, 06 May 2016 02:24:37 GMT socket.io:socket closing socket - reason transport close 

そして、これはありますnginxのログ:

2016/05/06 04:24:37 [error] 28383#0: *549 upstream timed out (110: Connection timed out) while reading upstream, client: xxx.xxx.xxx.xxx, server: api.tribeez.net, request: "GET /socket.io/?EIO=3&transport=websocket&t=LI3t1dh HTTP/1.1", upstream: "http://127.0.0.1:3010/socket.io/?EIO=3&transport=websocket&t=LI3t1dh", host: "api.tribeez.net" 

そして、このアプリのための私のnginxのconfに:

http { 
    map $http_upgrade $connection_upgrade { 
     default upgrade; 
     ''  close; 
    } 
} 

server { 
    server_name api.tribeez.net; 
    location/{ 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $host; 
     proxy_pass http://127.0.0.1:3010; 
    } 
    location /socket.io/ { 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $host; 
     proxy_pass http://127.0.0.1:3010; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection $connection_upgrade; 
    } 
} 

なぜそれが閉じられるのか?私はそれを定期的にpingする必要がありますか?

答えて

1

答えはNginx blogpostの下にあります:Nginxのバージョンを1.3.13+にアップグレードする必要がありました。インストール済み右Nginxは、Debianのリポジトリ(see instructions)を使用して、1.10(最新の安定)、そしてそれが今ここに:)

を正常に動作しているようだが、私のブラウザの出力はlocalStorage.debug = '*'を設定した後である:

socket.io-client:url parse https://api.tribeez.net +0ms 
socket.io-client new io instance for https://api.tribeez.net +5ms 
socket.io-client:manager readyState closed +2ms 
socket.io-client:manager opening https://api.tribeez.net +1ms 
engine.io-client:socket creating transport "polling" +2ms 
engine.io-client:polling polling +2ms 
engine.io-client:polling-xhr xhr poll +1ms 
engine.io-client:polling-xhr xhr open GET: https://api.tribeez.net/socket.io/?EIO=3&transport=polling&t=LI4PaE9 +2ms 
engine.io-client:polling-xhr xhr data null +2ms 
engine.io-client:socket setting transport polling +1ms 
socket.io-client:manager connect attempt will timeout after 20000 +3ms 
socket.io-client:manager readyState opening +3ms 
engine.io-client:polling polling got data ArrayBuffer +468ms 
engine.io-client:socket socket receive: type "open", data "{"sid":"0BCyhfQm--8uOQYUAAAb","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}" +5ms 
engine.io-client:socket socket open +1ms 
socket.io-client:manager open +0ms 
socket.io-client:manager cleanup +1ms 
socket.io-client:socket transport is open - connecting +0ms 
engine.io-client:socket starting upgrade probes +1ms 
engine.io-client:socket probing transport "websocket" +1ms 
engine.io-client:socket creating transport "websocket" +0ms 
engine.io-client:polling polling +2ms 
engine.io-client:polling-xhr xhr poll +0ms 
engine.io-client:polling-xhr xhr open GET: https://api.tribeez.net/socket.io/?EIO=3&transport=polling&t=LI4PaLo&sid=0BCyhfQm--8uOQYUAAAb +1ms 
engine.io-client:polling-xhr xhr data null +0ms 
engine.io-client:polling polling got data ArrayBuffer +252ms 
engine.io-client:socket socket receive: type "message", data "0" +1ms 
socket.io-parser decoded 0 as {"type":0,"nsp":"/"} +0ms 
engine.io-client:polling polling +2ms 
engine.io-client:polling-xhr xhr poll +0ms 
engine.io-client:polling-xhr xhr open GET: https://api.tribeez.net/socket.io/?EIO=3&transport=polling&t=LI4PaPo&sid=0BCyhfQm--8uOQYUAAAb +0ms 
engine.io-client:polling-xhr xhr data null +1ms 
engine.io-client:socket probe transport "websocket" opened +441ms 
engine.io-client:socket probe transport "websocket" pong +252ms 
engine.io-client:socket pausing current transport "polling" +1ms 
engine.io-client:polling we are currently polling - waiting to pause +1ms 
engine.io-client:polling polling got data ArrayBuffer +98ms 
engine.io-client:socket socket receive: type "noop", data "undefined" +1ms 
engine.io-client:polling pre-pause polling complete +0ms 
engine.io-client:polling paused +1ms 
engine.io-client:socket changing transport and sending upgrade packet +0ms 
engine.io-client:socket setting transport websocket +0ms 
engine.io-client:socket clearing existing transport polling +1ms 
engine.io-client:polling ignoring poll - transport state "paused" +0ms 

Socket.ioはそうとにかくポーリング接続を開くことができますが、後者が動作していればWebSocketを優先して停止します(私はそう思います...)

+0

私はまったく同じ問題に直面していますが、nginxはありません。私のsocketioクライアントが私のsocketioサーバから提供されています。それは異なるクライアント/サーバーのバージョンかもしれません...? –

+0

いいえ... ...詳細と新しい質問を投稿する可能性がありますか?私は個人的にあなたを助けるのに十分な知識がありません... – antoine129

+1

ああ、私は別の質問をして、それはウイルス対策だったと心配しないでください。それはウェブソケット接続をブロックしていました-_- –

関連する問題