我一直在try 用一个 node 设置HTTPS.我正在做的js项目.对于这个例子,我基本上遵循了node.js documentation:
// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
现在,当我
curl -k https://localhost:8000/
我明白了
hello world
正如所料.但如果我这么做了
curl -k http://localhost:8000/
我明白了
curl: (52) Empty reply from server
回想起来,这似乎是显而易见的,它将以这种方式工作,但同时,最终访问我的项目的人不会键入https://yadayada,我希望从他们访问网站的那一刻起,所有流量都是https.
How can 我明白了 node (and Express as that is the framework I'm using) to hand off all incoming traffic to https, regardless of whether or not it was specified? I haven't been able to find any documentation that has addressed this. Or is it just assumed that in a production environment, node has something that sits in front of it (e.g. nginx) that handles this kind of redirection?
这是我第一次涉足网络开发,如果这是显而易见的,请原谅我的无知.