简体   繁体   中英

Has anyone used Primus with websockets behind aws Elastic Load Balancer?

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. 在此处输入图片说明
  • Proxy server is set to "none" in configuration options. 在此处输入图片说明
  • TCP Listener is added in the Elastic Load Balancer configuration. 在此处输入图片说明
  • Proxy-Protocol is enabled as mentioned in the aws documentation . 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明
  • 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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM