Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websockets with socket.io on AWS Elastic Beanstalk

I'm trying to setup a websocket-server with socket.io on AWS Elastic Beanstalk. Got the initial request to /socket.io/1/?t=xxxx up and running but the websocket handshake fails with this error:

WebSocket connection to 'ws://xxxxxx.elasticbeanstalk.com/socket.io/1/websocket/a4DTCN2BeJZuiSaphVyz' failed: Unexpected response code: 502  

From googling and looking at the error 502 (Bad Gateway) it seems to have something to do with the nginx-proxy. So how do I configure the nginx to work with websockets?

Can't find anything in AWS documentation about setting up for websockets.

like image 616
funparko Avatar asked Apr 09 '13 16:04

funparko


People also ask

Is socket IO compatible with WebSocket?

Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.

Does AWS ALB support WebSockets?

ALB provides native support for WebSocket via the ws:// and wss:// protocols. HTTP/2 is a significant enhancement of the original HTTP 1.1 protocol. The newer protocol feature supports multiplexed requests across a single connection.

Does AWS ELB support WebSocket?

The Classic ELB doesn't support Websockets.

Do WebSockets work with load balancers?

The load balancer knows how to upgrade an HTTP connection to a WebSocket connection and once that happens, messages will travel back and forth through a WebSocket tunnel. However, you must design your system for scale if you plan to load balance multiple WebSocket servers.


2 Answers

you could try to go through the trouble of configuring nginx, but if you are only using websockets, it would be easier to turn off all proxys and directly connect.

this is under your app environment in the elastic beanstalk dashboard. There's a drop down button on the right marked "Actions". Select "Edit/Load Configuration"

enter image description here

like image 123
Adam Avatar answered Sep 23 '22 21:09

Adam


There is a significant disadvantage with the ditch-nginx approach. You will have to move https into node and also to your socket.io calls. It's much easier to manage https in the server configuration rather than in node.

If you don't need https I suggest dumping the proxy and just going directly to the node.

like image 45
Michael Draper Avatar answered Sep 23 '22 21:09

Michael Draper