I am trying to get https working on my nodejs server like so:
var http = require('http');
var https = require('https');
var fs = require('fs');
var express = require('express');
var privateKey = fs.readFileSync('server.key', 'utf8');
var certificate = fs.readFileSync('server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var app = express();
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080, ()=> {
console.log('Server started and listening on port 8080...')
});
httpsServer.listen(8443, ()=>{
console.log('Server started and listening on port 8443...')
});
When I run the server only the http url is working, the https gets timed out.
any idea why this is happening?
I am used to work with cpanel, so I setup the ssl cert on there already, but when it comes to node, I am hitting a wall.
2
Answers
Problem was the port wasn't forwarded.
It seems like there’s something wrong with your ssl files, You need to give certificate file and private key while creating https server like this:
Hope it helps.