Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade connection #167

Open
rmamba opened this issue Aug 10, 2024 · 0 comments
Open

Upgrade connection #167

rmamba opened this issue Aug 10, 2024 · 0 comments

Comments

@rmamba
Copy link

rmamba commented Aug 10, 2024

I'm having problems with connecting to server that is behind nginx reverse proxy that handles SSL certificates. Back end is unsecured so the upgrade of the connection is not working.

my nginx config for the WebSocket part:

location /ws {
  proxy_pass http://upstreamServer/ws;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $host;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header X-Real-IP $remote_addr;
  proxy_http_version 1.1;
  proxy_read_timeout 86400;
}

NodeJS code:

app.ws('/ws', function (ws, req) {
    console.log('Client connected');

    ws.on('close', function close() {
        console.log('Client disconnected...');
    });

    ws.on('upgrade', (request, socket, head) => {
        console.log('Upgrade connection');
        ws.handleUpgrade(request, socket, head, (websocket) => {
            console.log('Connection upgraded');
            ws.emit("connection", websocket, request);
        });
    });
});

I see Client connected and then righjt away Client disconnected messages in log file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant