apollographql / graphql-subscriptions

:newspaper: A small module that implements GraphQL subscriptions for Node.js
MIT License
1.58k stars 133 forks source link

Issue with Websocket proxy setting in Nginx #217

Open sspsinha opened 4 years ago

sspsinha commented 4 years ago
sspsinha commented 4 years ago

/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.

sannge commented 3 years ago

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; } }

bahachammakhi commented 3 years ago

Any solution for this @sannge @sspsinha ?

Cigan12 commented 2 years ago

@bahachammakhi any solution?)

Cigan12 commented 2 years ago

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 commented 2 years ago

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.