0

I’ve developed myself a little WebSocket Server which works perfectly (local - on my IDE). The problem is that I want to host it on my server managed with Plesk under a specific subdomain that I've created: ws.my-url.de.

This is my server.js file:

const {logInfo}       = require('./logger');
const WebSocketServer = require('ws').Server;
const express         = require('express');
const uuid            = require('node-uuid');

const app = express();
const wss = new WebSocketServer({
    server: app.listen(process.env.PORT || 8888)
});

logInfo('WebSocket Server successfully started');

wss.on('connection', ws => {
    ws.id = uuid.v4();

    logInfo(`Client connected: ${ws.id}`);

    ws.on('message', function () {
        logInfo(`New message from client: ${ws.id}`);
    });

    ws.on('close', function () {
        logInfo(`Client: ${ws.id} closed connection`);
    });
});

wss.on('close', function () {
    logInfo('WebSocket Server stopped');
});

app.post('/', function (req, res) {
    logInfo(req);
});

I've also implemented a logger that logs out to a file which works also great (directly on start e.g. my startup message) but inside the logs folder on my server is a yawning emptiness.

I really can't get my WebSocket Server running on my server. To leave no stone unturned, I've disabled the proxy mode from nginx but after trying to connect to wss://ws.my-url.de I'm getting this error:

WebSocket connection to 'wss://ws.my-url.de/' failed: Error during WebSocket handshake: Unexpected response code: 500

So I can say that my server is not starting. To be really sure (and to exclude other things), I've wrote a little http server found in the internet and this ran straight out of the box after pressing the Restart App button (I saw the response in the browser window):

const http = require('http');

http.createServer(function(request, response) {
  response.writeHead(200, {'Content-Type': 'text/html'});
  response.end('App is running…');
}).listen(process.env.PORT);

This is my configuration by the way:

enter image description here

When I open the URL after trying to start my WebSocket Server, I'm getting this error:

enter image description here

So what I'm doing wrong here? I don't want a page I can open, I just want to get this running as a little service which is accessible over my subdomain. I'm very overwhelmed with this and thankful for every person who can help me.

Mr. Jo
  • 4,946
  • 6
  • 41
  • 100
  • Did you check this answer? https://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss – Adinarayana Immidisetti Apr 04 '20 at 05:18
  • Nope. But why is my server not starting? Does express don’t work? – Mr. Jo Apr 04 '20 at 07:27
  • No one has an answer? – Mr. Jo Apr 04 '20 at 17:56
  • Maybe it’s a problem with passenger which serves the app? – Mr. Jo Apr 04 '20 at 21:03
  • This is more like an SSL related issue because of improper SSL/Network config between two services(client-server), There are a handful of reasons to get an unsuccessful SSL handshake, Also it looks like your app started but failed during the establishment of the secure connection. why can't you first try with nonsecure 'ws' instead 'wss' ? – Adinarayana Immidisetti Apr 04 '20 at 21:37

1 Answers1

0

You must change the application mode from production to development to see the real issue behind that error message because the app is not even running, it could be something as simple as not having npm install.

Also websockets only work on Plesk if apache proxy is disabled, so you should only use ngnix.

There’s no problem on putting them on a subdomain, I have done it on Plesk running on aws lightsail multiple times. Ex. Api.domain.com