When I use http protocol no problem happened,but then I deploy my project on https protocol,it case 'Error during WebSocket handshake: Unexpected response code: 400',How to solve this problem?
This is my nginx Config.
upstream site {
server 127.0.0.1:3000;
}
server {
listen 443;
charset utf-8;
client_max_body_size 75M;
ssl on;
ssl_certificate /etc/nginx/ssl/site_cert.crt;
ssl_certificate_key /etc/nginx/ssl/site.key;
location / {
include proxy_params;
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://site;
}
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://site/socket.io;
}
}
Is it only WebSocket that is failing, or the HTTP routes as well?
Is the 400 error returned by nginx, or is the application returning it?
Only websocket is failing,HTTP routes work OK.
Over http, it works on polling and websocket success.
Over https,it works on polling success,but websocket failed.
I can't find where error is returned by.
I can't find where error is returned by
how so? Is the application receive the request? If yes, then the error comes from the app. If the request never reaches the app, then the error comes from nginx.
Also, you may want to go over all the comments on https://github.com/socketio/socket.io/issues/1942, as many other people apparently have seen this problem and found a few things to change in the ngnix config to fix it.
application doesn't receive request,I think I should do some changes in the nginx config to try to solve this problem.
@jarrai Hi, I am facing the same issue. Can you elaborate on how you rectified it? Thank You
I was facing this issue when using Elastic Beanstalk and an AWS load balancer.
Websockets travel over tcp, not http, so we needed to tell the load balancer to forward raw tcp instead of operating at the http layer.

Sorry to comment on a closed issue, but I hope this is helpful for some people.
Solved! thanks bgschiller
Most helpful comment
I was facing this issue when using Elastic Beanstalk and an AWS load balancer.
Websockets travel over tcp, not http, so we needed to tell the load balancer to forward raw tcp instead of operating at the http layer.
Sorry to comment on a closed issue, but I hope this is helpful for some people.