Node.js and express and production ssl certificate -
i'm having problems implement ssl certificate using node.js.
everything works fine localhost, move ubuntu server, multiple problems occur.
i've minimized following code.
certificates (.crt) , keys (.key) in certificates directory, names localhost.key or examplesslserver.crt. i'm using rapidssl certificate , told needed include intermediate certificate.
function serverssl(host,port,intermediate) { var https = require('https'); var fs = require('fs'); var express = require('express'); var app = express(); var httpsoptions = { key: fs.readfilesync('certificates/' + host + '.key'), cert: fs.readfilesync('certificates/' + host + '.crt') }; if (intermediate) { httpsoptions.ca = [fs.readfilesync('certificates/' + intermediate + '.crt')]; } var server = https.createserver(httpsoptions, app).listen({ port: port, host: host }, initserver); function initserver() { var host = server.address().address, port = server.address().port; console.log( 'example app listening @ https://%s:%s', host, port); } app.get('/hello', function (req, res) { var msg = 'hello ssl'; console.log(msg); res.send(msg); }); }
i've tried 2 different calls either
- serverssl('localhost',8445);
- serverssl('examplesslserver.com',8445,'intermediate')
localhost works fine, when use server, following stack error:
error: listen eaddrnotavail 52.xxx.xxx.xxx:8445 @ object.exports._errnoexception (util.js:873:11) @ exports._exceptionwithhostport (util.js:896:20) @ server._listen2 (net.js:1237:19) @ listen (net.js:1286:10) @ net.js:1395:9 @ getaddrinforeqwrap.asynccallback [as callback] (dns.js:64:16) @ getaddrinforeqwrap.onlookup [as oncomplete] (dns.js:83:10)
if take out host argument, doesn't fail, doesn't respond. changed code slight use http vs. https , things seem work fine. also, i've tried many different ports, same problem occurs.
their might problem ssl certificate, have no easy way debug it. i'd happy try tool.
in case, appreciated.
Comments
Post a Comment