I
I
Ivan Kondratiev2015-12-14 11:00:46
Node.js
Ivan Kondratiev, 2015-12-14 11:00:46

How to make friends socket server on Nodejs and https?

Hello. Please guide me or point me in the right direction.
Problem:
There is a server on which the site is hosted ( php ), nodejs
was also installed on this server. Raised a socket server on it. Everything works fine on the dev server.
On the combat protocol https , I didn’t want to connect to it at all. The admin messed something up and the nodejs server became available via the http protocol when accessing it directly through the browser. But when my js script connects to the socket, it gives this error

Mixed Content: The page at ' https://xxxx_test.ru/ ' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ' http://xxxx_test.ru:8888/socket.io/?EIO=3&transpor... ' . This request has been blocked; the content must be served over HTTPS.

Tell me how to fix this?
And which option is better:
Nodejs server directly on the same server as the site or on a completely different server?
THX.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2015-12-14
@bingo347

If the page is loaded via https, then all ajax requests must go via https, and websockets via wss - this is
the
security
policy node server through the https module and not http (how to do this is in the socket.io dock)

I
Ivan Kondratiev, 2015-12-16
@inik23

I start the server via https

var https = require('https');
var fs = require('fs');

var files = ["***************.crt", "***************.crt"];
var file;

var ca = (function() {
    var _i, _len, _results;
    _results = [];
    for (_i = 0, _len = files.length; _i < _len; _i++) {
        file = files[_i];
        _results.push(fs.readFileSync('/etc/ssl/tcerts/' + file));
    }
    return _results;
})();

httpsOptions = {
    ca: ca,
    key: fs.readFileSync('/etc/ssl/tcerts/******.key', 'utf8'),
    cert: fs.readFileSync('/etc/ssl/tcerts/*****.crt', 'utf8')
};
https.createServer(options, function (req, res) {
    res.writeHead(200);
    res.end("hello world\n");
}).listen(8888);

It starts but is not available on https://domen:8888
When I make an http server, it is available on https://domen:8888
Not clear strangeness. Tell me what could be the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question