D
D
Dmitry Maslennikov2017-04-21 15:35:09
Node.js
Dmitry Maslennikov, 2017-04-21 15:35:09

How to make WebSockets work on HTTPS?

I recently switched the server to HTTPS, after the transition WebSockets stopped working.

The protocol has been changed from ws to wss on the client. On the server (running on NODE JS), certificate files were also connected and the necessary settings were made. As a result, now an error is thrown on clients:

WebSocket connection to ' wss://XXX.XX.XXX.XXX:4433/ ' failed: WebSocket opening handshake was canceled


Server side code in Node JS:

var https = require('https');
    var WebSocketServer = require('ws'), fs = require('fs');
    var port = 4433; 
    var app	= null;

    var processRequest = function( req, res ) {
        res.writeHead(200);
        res.end("All glory to WebSockets!\n");
    };

    app = https.createServer({
        key: fs.readFileSync('/etc/nginx/ssl/server.key'),
        cert: fs.readFileSync('/etc/nginx/ssl/bundle.crt'),
    requestCert: true,
    rejectUnauthorized: false,
    }, processRequest ).listen(port);

    var webSocketServer = new WebSocketServer.Server( { server: app } );


How to make Websockets friends with HTTPS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2017-04-21
@aprenoir

Obviously the browser sends your certificate
to hell

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question