Connecting to Websocket returns 400 (Prod, Proxy)

I installed my meteor app on my Ubuntu 16.04.2 LTS Server. My app itself is running fine but I wonder about the following message:

WebSocket connection to 'ws://myapp.tld/sockjs/790/fu9qi2bo/websocket' failed: Unexpected response code: 400

Since I also have Plesk installed to manage my apps, the app is running via Phusion Passenger that also runs behind an nginx proxy with default settings from Plesk.

I tried several nginx proxy settings, that I found on SO or other website but I only get the error message.

Someone here, who made it through?

1 Like

Ok I found the answer myself.

The most nginx directives I found online were either using localhost or the public ip. My one is using a b-class private subnet ip and also add a read and send timeout to a high value to prevent ws disconnect after 60 seconds.

location /app {
	proxy_pass http://privateip:port;
	proxy_http_version 1.1;
	proxy_read_timeout 36000s;
	proxy_send_timeout 36000s;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
	proxy_set_header Host $host;

I added this
proxy_send_timeout 60s;
and it solved my problem , now my configuration looks like this.
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; # allow websockets
proxy_set_header Connection “upgrade”;
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP
proxy_read_timeout 60s;

I got some inspiration from the following thread too.

it seems that nginx as a proxy turns off the socket connection if proxy_send_timeout is not explicitly specified.
I use let’s encrypt though, and use option 2 to only allow https connection.
Not sure whether it’s default behavior of nginx or because I use let’s encrypt.

1 Like

Hi @donyang I just found out the same config by luck but I can confirm that it’s working (in casw someone else with the same problem is reading this topic)