我正在尝试调整angular-seed 项目中包含的节点服务器以服务 SSL。基于这个例子,他们有:
// HTTPS
var https = require('https');
// read in the private key and certificate
var pk = fs.readFileSync('./privatekey.pem');
var pc = fs.readFileSync('./certificate.pem');
var opts = { key: pk, cert: pc };
// create the secure server
var serv = https.createServer(opts, function(req, res) {
console.log(req);
res.end();
});
// listen on port 443
serv.listen(443, '0.0.0.0');
我尝试了以下,它似乎运行(没有记录错误),但是当我导航到https://localhost:8000/home
我得到“这个网页不可用” http://localhost:8000/home
- 非 SSL - 在我入侵节点服务器之前工作。我怎样才能让它作为 SSL 工作?
#!/usr/bin/env node
var util = require('util'),
http = require('http'),
fs = require('fs'),
url = require('url'),
https = require('https'),
events = require('events');
// read in the private key and certificate
var pk = fs.readFileSync('./scripts/privatekey.pem');
var pc = fs.readFileSync('./scripts/certificate.pem');
var opts = { key: pk, cert: pc };
var DEFAULT_PORT = 8000;
function main(argv) {
// create the secure server
new HttpServer({ key: pk, cert: pc,
'GET': createServlet(StaticServlet),
'HEAD': createServlet(StaticServlet)
}).start(Number(argv[2]) || DEFAULT_PORT);
}
[... balance of script omitted ...]