Installing SSL Certificate On Node Server

node.js, socket.io, ssl

Solution

If you want to run a node.js app on port 3000 with (behind) HTTPS, then you need to set up a proxy service on port 443 to proxy HTTPS requests to port 3000.

You didn't mention what server you have running on port 443 right now (is it Apache?) but you might want to

- move that service to a new port (e.g. 4000), then run a node http proxy on port 443 that handles HTTPS.

- Then set up a subdomain for the node.js app that you have running on port 3000 (e.g. blah.gatherify.com).

- Then, using node http proxy, you will proxy all requests that are made to "gatherify.com" to port 4000, and all requests that are made to "blah.gatherify.com" to port 3000.

When all is set up properly, users can visit "https://gatherify.com" or "https://blah.gatherify.com" (without using :port numbers) and it'll all be secured with SSL. ;)

Problem

I created a self-signed certificate and installed it on apache as well as on node.js(port 3000). On localhost both `https://localhost` and `https://localhost:3000` works well. So, I bought GoDaddy Standard SSL certificate and installed it on the server(`http://gatherify.com`). Now `https://gatherify.com` works well, but ssl on node isn't working. When I access `https://gatherify.com:3000` i get "The connection was interrupted". I executed curl: ``` root@host [~]# curl -v -s -k https://gatherify.com:3000 * About to connect() to gatherify.com port 3000 (#0) * Trying 108.160.156.123... connected * Connected to gatherify.com (108.160.156.123) port 3000 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * warning: ignoring value of ssl.verifyhost * NSS error -5938 * Closing connection #0 * SSL connect error ``` Any suggestions to fix this? UPDATE *SERVER SIDE :* ``` var io = require('socket.io'), connect = require('connect'), fs = require('fs'), var privateKey = fs.readFileSync('cert/server.key').toString(); var certificate = fs.readFileSync('cert/server.crt').toString(); var options = { key: privateKey, cert: certificate }; var app = connect(options).use(connect.static('../htdocs/node/')); app.listen(3000); var server = io.listen(app); server.sockets.on('connection', function(socket) { console.log("Connected"); }); ``` CLIENT SIDE: ``` <html> <head> <script type = "text/javascript" src = "https://gatherify.com:3000/socket.io/socket.io.js"></script> <script type = "text/javascript"> var socket = io.connect('https://gatherify.com:3000', {secure:true}); </script> </head><body></body></html> ```

Original source