javascript - Meteor WebSocket connection to 'ws://.../websocket' failed: Error during WebSocket handshake: Unexpected response code: 400 -
i brand new things meteor.js, , wondering error. started test project (with button click meter) , works, go console , see websocket connection 'ws://shibe.ninja/sockjs/243/5gtde_n9/websocket' failed: error during websocket handshake: unexpected response code: 400
don't know how fix it. thanks
i bumped problem myself, i had proxy headers set correctly , still not working. apparently cloudflare causing issues. here great article on subject: https://meteorhacks.com/cloudflare-meets-meteor
as far i've found, there 3 solutions:
option 1: use cloudflare enterprise, supports sockets.
option 2: disable meteor websockets, affect performance fallbacks use sock.js replacment. this, set meteor environment this:
export disable_websockets=1
option 3: in cloudflare, create ddp subdomain websocket (ddp.yourdomain.com), disable cloudflare on new subdomain. after set meteor environment this:
export ddp_default_connection_url=http://ddp.example.com
after nginx config needed adjustments, has become cross-origin (cors) setup. new nginx config:
map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80 proxy_protocol; listen [::]:80 proxy_protocol; server_name mydomain.com ddp.mydomain.com; ## allows cors setup work add_header access-control-allow-origin 'http://example.com'; ## hides cors setup meteor server ## without header added twice, not sure why? proxy_hide_header access-control-allow-origin; ## idealy 2 options above should disabeled, ## use 1 instead, caused issues in setup. # proxy_set_header access-control-allow-origin 'http://example.com'; location / { proxy_pass http://localhost:3000; proxy_set_header host $host; # pass host header proxy_set_header upgrade $http_upgrade; # allow websockets proxy_set_header connection $connection_upgrade; proxy_set_header x-real-ip $remote_addr; # preserve client ip proxy_set_header x-forwarded-for $remote_addr; proxy_http_version 1.1; # meteor browser cache settings (the root path should not cached!) if ($uri != '/') { expires 30d; } } }
finally, remember restart nginx.
Comments
Post a Comment