Ssl – Socket IO combined with apache ssl server

apache-2.4node.jssocketssl

I'm trying to run a NodeJS server on port 8000 along with my Apache server which has a ssl certificate. I'm using virtual hosts and proxypass to link from my apache website through the /node path to my NodeJS server.

The problem I'm having right is that I'm able to load the pages served with the Express plugin but the polling from SocketIO connections seem to fail. I've tried a bunch of things but I just cant seem to get it to work.

If I setup my client to listen to

var socket = io.connect('example.com:8000', {secure: false});

My console show something along the lines of this:

socket.io-1.3.7.js:2 GET https://example.com:8000/socket.io/?EIO=3&transport=polling&t=1451044647116-0 net::ERR_CONNECTION_CLOSED

Also, I know how to use SSL with my NodeJS server but I assume isn't going to work since I'm also listening through port 443 with my apache server.

Anyone knows if this is even possible and/or how to set this up?

EDIT: Forgot to mention I'm running on Ubuntu 14.04 x64

Best Answer

I've finally figured it out.

Server side I run the following code on my nodeJS app:

var options = {
    key: fs.readFileSync('/home/certificates.key'),
    cert: fs.readFileSync('/home/certificates.crt'),
    requestCert: true
};
var server = require('https').createServer(options, app);
var io = require('socket.io').listen(server);
server.listen(8000);
console.log('Server started at port: 8000');

Client side I serve a page using my Apache server which simply uses the following to establish the connection.

var socket = io.connect('example.com:8000', {secure: true});

I never realized you could run ssl over a port like 8000 in this way.