문제

I use node.js and socket.io for our chat application and everything works good until we decide to implement SSL certificate.

Before SSL our SocketServer connect like this:

// Start up a Node server with Socket.IO
var io = require('socket.io').listen(8080,{
  'log level':1
});

and Socket like this

socket : io.connect('http://111.111.111.111:8080'),

After we implement we setup the Proxy directives under domain. Now any requests that are sent to https://example.com/nodejs will be passed to localhost:8080. So I changed connection like this:

// Instantiate the Socket.IO client and connect to the server
socket : io.connect('https://example.com/nodejs'),

But the connection faild and redirect to 404 page. I don't know where can be the problem so I need your help.

Thanks

도움이 되었습니까?

해결책

Socket.io page not found cause it listen on http server and the website js connect to it by https, this is my solution, hope it helpful:

var https = require('https');
var express = require('express');
var app = express();

// app.use ...
// app.set ...

var credentials = {
    key: fs.readFileSync('./config/privateKey'),
    cert: fs.readFileSync('./config/certificate')
};

var https_server = https.createServer(credentials, app);

var io = SocketIO.listen(https_server, {});

io.set('authorization', function(handshakeData, callback) {
    // ...
});

io.sockets.on('connection', function(socket) {
    // ...
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top