CNode

如何用Express搭建一个https服务器

问答
9972389149发布于8 年前最后回复8 年前3 回复3232 浏览0 收藏

服务器是腾讯云的,证书已经颁发了,但express默认搭建的是http服务器,我想把他转为https,要如何操作,求教啊

查看回复

回复 (3)

Z
zuohuadong#1·8 年前
M
maiime#2·8 年前
const fs = require('fs')
const express = require('express')

const privatekey = fs.readFileSync('./ca/private.key', 'utf8')
const certificate = fs.readFileSync('./ca/full_chain.pem', 'utf8')

const app = express()

const http = require('http').Server(app)
const https = require('https').Server({
    key: privatekey,
    cert: certificate
}, app)
J
jinzhan1010#3·8 年前

分享下koa的 const app = new Koa() const options = { key: fs.readFileSync('xxx.key'), cert: fs.readFileSync('xxx.pem') } https.createServer(options, app.callback()).listen(port)

参与回复
登录后即可参与回复。登录