美文网首页
让Node.js 支持https协议

让Node.js 支持https协议

作者: Tme_2439 | 来源:发表于2019-07-22 11:15 被阅读0次

配置如下:

const express = require('./node_modules/express')
const app = express()
const path = require('path')
const fs = require('fs')
var https  = require('https') // 一、引入https模块
const port = process.env.PORT || 3003

// 二、同步读取密钥和签名证书(腾讯云的免费证书文件)
var options = {
    key: fs.readFileSync('../keys/2_zhulijun.club.key'),
    cert: fs.readFileSync('../keys/1_zhulijun.club_bundle.crt')
}
var httpsServer = https.createServer(options, app) // 三、创建服务
httpsServer.listen(3002, ()=>{ // 四、监听端口
    console.log(`https服务启动成功:https://localhost:3002`)
})
app.listen(port, () => {
    console.log('http服务启动成功:http://localhost:3003')
})

相关文章

网友评论

      本文标题:让Node.js 支持https协议

      本文链接:https://www.haomeiwen.com/subject/fruilctx.html