AWS EB: Error during WebSocket handshake: Unexpected response code: 400


There is a Laravel/Vue.JS app hosted on AWS behind a Classic Load Balancer (Elastic Beanstalk) and proxied internally via Nginx down to server.
SSL is terminated on the Nginx.

This is the nginx config:

Right now the long-polling mode works fine, but it fails to initiate an upgrade:

WebSocket connection to ‘wss://’ failed: Error during WebSocket handshake: Unexpected response code: 400

P.S Chrome’s Frames tab I can only see this weird message: (Opcode -1)

Has anybody successfully got working on an AWS Elastic Beanstalk environment? I just wasted two weeks dealing with this issue, would be very thankful for ANY suggestions or ideas. Thanks!

Update. I turned on a verbose logging and here are the variables within Nginx:

Maybe someone will find some of these values incorrect so I would appreciate any advise.


Is your ELB using HTTP/HTTP listeners or TCP/SSL listeners? Websockets only works on the latter protocol types. Change the listener to TCP and it will work.

Alternatively, if you built your environment using CLI or API, you can also rebuild your ElasticBeanstalk App using an Application Load Balancer (ALB) instead of a Classic Load Balancer (ELB) as the ALB also supports websockets. This option is not available via the web console.

Leave a Reply