Websockets with socket.io on AWS Elastic Beanstalk

2019-01-14 15:27发布

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.

3条回答
我命由我不由天
2楼-- · 2019-01-14 15:39

Socket.io defaults to port 8080. Make sure port 8080 is enabled on your EC2 Security Group by adding a "Inbound > Custom TCP Rule" in the AWS Admin > EC2 > Security Groups.

查看更多
唯我独甜
3楼-- · 2019-01-14 15:40

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.

查看更多
唯我独甜
4楼-- · 2019-01-14 15:52

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

查看更多
登录 后发表回答