简体   繁体   English

如何配置nodejs / expressjs通过https服务页面?

[英]How do I configure nodejs/expressjs to serve pages over https?

I have a certificate and key, and I'm looking to serve my pages over https. 我有一个证书和密钥,我希望通过https服务我的页面。 How do I configure nodejs/expressjs to do so? 如何配置nodejs / expressjs来做到这一点?

I'm explicitly looking to do this through the expressjs library. 我正在明确地希望通过expressjs库做到这一点。

if you use 0.2.4. 如果您使用0.2.4。 you can use 您可以使用

var express = require('express');
var fs = require("fs");
var crypto = require('crypto');

var app = express.createServer();
var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();
var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
app.setSecure(credentials);

but this not possible if you use node 0.4, as you can't call setSecure() to convert a server as SSL. 但是,如果您使用节点0.4,则无法实现此操作,因为您无法调用setSecure()将服务器转换为SSL。 One must create an instance of https.Server. 必须创建一个https.Server实例。

i don't know if there are any future plan to support this 我不知道将来是否有任何计划来支持这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM