graphql-subscriptions icon indicating copy to clipboard operation
graphql-subscriptions copied to clipboard

Issue with Websocket proxy setting in Nginx

Open sspsinha opened this issue 6 years ago • 6 comments

sspsinha avatar Jan 31 '20 07:01 sspsinha

/WebSocket connection to 'ws://localhost:9097/graphql' failed: Error during WebSocket handshake: Unexpected response code: 405

/Issue while hosting the graphql server on nginx

/Nginx.config websocket server setting

            listen       9097;
	server_name  localhost;
	location /subscription{			
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_pass http://localhost:3007;
	}

My graphql server is running locally on localhost:3007/graphql. But with above configuration socket is not getting created.

Getting below error:

WebSocket connection to 'ws://localhost:9097/graphql' failed: Error during WebSocket handshake: Unexpected response code: 405.

sspsinha avatar Jan 31 '20 07:01 sspsinha

same issue here, getting this error from frontend, client.ts:557 WebSocket connection to 'ws://localhost:8080/graphql' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

here is my setup, server { location / { proxy_pass http://web:8080; } }

sannge avatar Feb 09 '21 22:02 sannge

Any solution for this @sannge @sspsinha ?

bahachammakhi avatar Jun 12 '21 21:06 bahachammakhi

@bahachammakhi any solution?)

Cigan12 avatar Feb 02 '22 09:02 Cigan12

I have this configuration for nginx image And this one in nestjs image And the postman returns 400 when I'm trying to connect image

For browser the same

Cigan12 avatar Feb 02 '22 09:02 Cigan12

So, I've found the solution, the problem was in postman, I don't know why, but websockets there is working inappropriate, btw, some problem was with nginx, I had two of them, on inside the docker container and the second main on the server, and I need to add the same thing (proxy_set_header etc.) to both of nginxs.

Cigan12 avatar Feb 08 '22 07:02 Cigan12