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년 전18291회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠