Is there a way to Implement WebSockets on AWS’s ELB (Elastic Load Balancer)

0

I am trying to experiment to implement my website with an Amazon ELB (Elastic Load Balancer).

I was successfully able to implement the Web part using an HTTPS-based Elastic load balancer, however, my website uses Web Sockets for the Chat session, which seems to be an issue on that to get it working.

WSS based socket running on a different port like 6400, it seems to be error out within the ajax request to chat port with "xmlhttprequest" saying "Access-Control-Allow-Origin" is set to same site.

Access to XMLHttpRequest at 'https://www.example.com:5000/socket.io/?EIO=3&transport=polling&t=N4gTtJ6' from origin 'https://www.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

If we take out the ELB this works fine, however if we enable the ELB it seems to be blocking the WSS port or requests for some reason saying above error.

The webserver is Nginx and Chat runs on Express module engine using NodeJS, on Centos 7.4

mahen3d
已提問 4 年前檢視次數 18290 次
3 個答案
2

ALBs support websockets (https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/)

ALB provides native support for WebSocket via the ws:// and wss:// protocols.

NLBs support websockets (https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-listeners.html#listener-configuration)

You can use WebSockets with your listeners.

Obviously, you need to have a listener/target group on the websocket port. Websockets should be inherently stickly (at least on the alb https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html.

WebSockets connections are inherently sticky. If the client requests a connection upgrade to WebSockets, the target that returns an HTTP 101 status code to accept the connection upgrade is the target used in the WebSockets connection. After the WebSockets upgrade is complete, cookie-based stickiness is not used.

已回答 4 年前
0

I confront the same issue with application load balancer. ALB blocks the websocket connection. It works fine without ALB (with direct access to IP). I enabled the stickiness of the target group. How can we use websocket with ALB?

nemy
已回答 2 年前
0

I have an ALB that has 1 target group that has 3 instances. I need to subscribe on the socket on ALL 3 instanses via an ALB, because IDK from where the data will come (i use the kafka and send the data via the socket).

How can i achive this ? For now i subscribed only on one of them, and i lost some data

Alex
已回答 3 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南