How do you fix Websocket error


#1

I deployed my app to to a fresh digital ocean server using Meteor Up (mup) but I get this error all the time:

WebSocket connection to 'ws://mycoolsite.com/sockjs/087/aa0q84d7/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

The app still works as expected (CRUD) but I think this error is causing my problems with me uploading files.

How can I fix this?


#2

having the same issu =/


#3

I’m having the same issue in Digital Ocean + Nginx + Meteor using MeteorUp tool :pensive:


#4

I’ve removed kadira and it helped me. Try to remove or upgrade this package


#5

I am using the exact same set up, no kadira in my setup. 1 thing is that my app still works fine but I do not know what is causing this error and would prefer to fix it


#6

I solve my issue, in fact in my case it was the Cloudflare, and I solved following this post: https://meteorhacks.com/cloudflare-meets-meteor


#7

I have found that many servers don’t support websockets by default, in my case an EC2 instance im going to solve this probably by installing NGINX on it. I think we all have to check for that first on the server we using.


#8

how to config server with websockets support?


#9

Solution to this deployment error as well as other challenges related to HTTPS are most easily solved by using nginx as a reverse proxy. Short of it is external incoming connections from 80/443 (including websocket traffic) are intercepted by nginx which handles SSL/TLS … traffic is then simply forwarded to your meteor app which has become a nodejs app as a result of issuing :

meteor build --directory  /output/dir

On your server you run nginx + nodejs + mongo (as docker containers, or not )

Here is a working nginx.conf

# we're in the http context here
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}


server {
    listen 80;
    listen 443 ssl http2;
    server_name cubralibre.com www.cubralibre.com;


    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers On;

    ssl_certificate /etc/letsencrypt/live/cubralibre.com/fullchain.pem;
    ssl_certificate_key   /etc/letsencrypt/live/cubralibre.com/privkey.pem;

    ssl_session_cache shared:SSL:128m;

    add_header Strict-Transport-Security "max-age=31557600; includeSubDomains";
	add_header X-Content-Type-Options "nosniff" always;
	add_header X-Frame-Options "SAMEORIGIN" always;
	add_header X-Xss-Protection "1";
	# add_header Content-Security-Policy "default-src 'self'; script-src 'self' *.google-analytics.com";

	# add_header Content-Security-Policy "default-src 'self'";

    ssl_stapling on;
    ssl_stapling_verify on;

    # Your favorite resolver may be used instead of the Google one below
    resolver 8.8.8.8;

    # root /var/www/demo;
    # index index.html;

    # location '/.well-known/acme-challenge' {
        # root        /var/www/demo;
    # }

    location / {

        if ($scheme = http) {
            return 301 https://$server_name$request_uri;
        }

		# proxy_pass      http://127.0.0.1:8080;
		proxy_pass      http://localhost:3000;

		proxy_redirect off;
		proxy_intercept_errors on;

		#error_page 500 = /error_page.html;

		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

		proxy_http_version 1.1; # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

		proxy_set_header Upgrade $http_upgrade;
		# proxy_set_header Connection "upgrade";
		proxy_set_header Connection $connection_upgrade;
		proxy_set_header Host $host;  # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass

	}
}

#10

I am getting and error WebSocket connection to 'wss://*’ failed: Error during WebSocket handshake: Unexpected response code: 200 while running a meteor app on Centos Apache 2.2, the httpd conf is as follows
SSLEngine on
SSLProxyEngine On
ProxyRequests Off
ProxyPass / http
localhost:8300/
ProxyPassReverse / htp
localhost:8300/

RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* wss://localhost:8300/%{REQUEST_URI} [P]

the app runs on port 8300, and the domain is https://mondozapp.com, i get this error only while accessing the site through https, if I go to mondozapp.com:8300 everything is good. Please help, struggling with this for past 4 days :slight_smile:


#11

I am having the same issues with websockets. But in my case my whole development machine is affected. Other web sites are slow to load and even slack has trouble updating. Other people in my group have noticed the same from time to time. The fix seems to be shutting off wifi and turning it back on.

I was wondering if others experience the same issues when these websocket problems start or if the websocket issue are a result of something else slowing down my machine. We use macs.