PhoenixChannel over wss failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

Hi all,

Trying to get Phoenix Socket Service (in an Ember front end app) to connect to a Phoenix app but I’m getting the following error when using wss:

failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

Things work in dev when using ws only. Not sure if I’d be able to get wss working in dev?

In production, given my content is restricted to https, wss is the only allowed option.
I have to admit, first time attempting to deploy with forced websocket secure traffic but I managed to get nginx proxy /websocket/ to the backend but still get the following error knowing that I have a self-signed cert on the server:

failed: Error during WebSocket handshake: Unexpected response code: 200

What can I do to get this working in dev and prod?
Any and all hints are appreciated, so thanks in advance!

I’ve changed the websocket location path defined in nginx to match what Ember is using for the request, so now the nginx stanza reads like this:

  location /socket/websocket {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_read_timeout 86400;
  }

and now I get the following (in production):

failed: Error during WebSocket handshake: Unexpected response code: 403

I’ve overcome this issue by setting the WebSocket protocol per environment instead of forcing wss in dev …

2 Likes

Can you explain a little more how you manage to overcome this issue?

The
" I’ve overcome this issue by setting the WebSocket protocol per environment instead of forcing wss in dev …"

best regards

1 Like

@Dado sorry I’ve been away from development for some time and haven’t maintained good presence here either.
The dev environment changed drastically but I’d imagine I’ve made a change to something in Nginx. Sorry I don’t have the old config to dig out what I did!