如何配置nodejs/expressjs通过https服务页面? [英] How do I configure nodejs/expressjs to serve pages over https?

查看:33
本文介绍了如何配置nodejs/expressjs通过https服务页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个证书和密钥,我希望通过https服务我的页面.如何配置nodejs/expressjs来做到这一点?

I have a certificate and key, and I'm looking to serve my pages over https. How do I configure nodejs/expressjs to do so?

我正在明确地希望通过expressjs库做到这一点.

I'm explicitly looking to do this through the expressjs library.

推荐答案

(如果使用0.2.4).您可以使用

if you use 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);

,但是如果使用节点0.4,则无法实现,因为您无法调用setSecure()将服务器转换为SSL.必须创建一个https.Server实例.

but this not possible if you use node 0.4, as you can't call setSecure() to convert a server as SSL. One must create an instance of https.Server.

我不知道将来是否有任何计划来支持这一点

i don't know if there are any future plan to support this

这篇关于如何配置nodejs/expressjs通过https服务页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆