Answer the question
In order to leave comments, you need to log in
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.
Answer the question
In order to leave comments, you need to log in
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 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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question