Has anyone used Primus with websockets behind aws

2019-09-10 04:48发布

I have a node.js application server running on port 80 and I recently added realtime messaging through Primus websockets transformer on port 9001.

It works well in single instance. I deployed the messaging to Beanstalk environment with the following configuration.

AWS Elastic Beanstalk
Platform version v2.0.0
Nodejs version v0.12.6
Primus version v4.0.5
  • Port 9001 is added to the security group of the instance as shown in the screenshot. enter image description here
  • Proxy server is set to "none" in configuration options. enter image description here
  • TCP Listener is added in the Elastic Load Balancer configuration. enter image description here
  • Proxy-Protocol is enabled as mentioned in the aws documentation. enter image description here enter image description here enter image description here
  • Added proxywrap to the primus server configuration.

But the client requests doesn't reach the instance and connection timed out. Has anyone used primus with websockets behind AWS ELB? Please let me know the configuration which enables websockets communication behind Elastic Beanstalk.

2条回答
甜甜的少女心
2楼-- · 2019-09-10 05:03

You need to do two things

Increase idle timeout on ELB

On EC2 dashboard, reach for Load Balancer settings and open the Description tab for your load balancer. Look for the setting "Idle timeout", type something like "600" (for 10 minutes)

Ping periodically

Implement a WS ping every 5 minutes (or other, but need to be lower than the idle timeout on ELB). If primus doesn't have support on its API, implement yourself sending of a dummy message to client.

查看更多
聊天终结者
3楼-- · 2019-09-10 05:20

I managed to get websockets (https://github.com/websockets/ws) working on both port 80 and 8080 on ELB with the configurations below. And thats without enabling Proxy-Protocol.

Security group:

https://cloud.githubusercontent.com/assets/3421858/14969922/ff6659f4-10bc-11e6-903c-168a530efebd.png

Load balancer listeners:

https://cloud.githubusercontent.com/assets/3421858/14969937/160c7544-10bd-11e6-8357-a11f5481d9fd.png

Container options:

https://cloud.githubusercontent.com/assets/3421858/14969950/38776f1c-10bd-11e6-961b-aabbf0ab1d66.png

Load balancer:

https://cloud.githubusercontent.com/assets/3421858/14969983/6c4f47ce-10bd-11e6-8fa0-eb8180ffb281.png

查看更多
登录 后发表回答