腾讯云申请免费DV SSL证书 申请完的证书压缩包
需要用到nginx下的两个文件 上传到服务器
使用:
const express = require("express");
const path = require("path");
const https = require("https");
const fs = require("fs");
const app = express();
// 填入文件地址
const privateKey = fs.readFileSync("../../Nginx_SSL/2_hongbin.xyz.key", "utf8");
const certificate = fs.readFileSync(
"../../Nginx_SSL/1_hongbin.xyz_bundle.crt",
"utf8"
);
const credentials = { key: privateKey, cert: certificate };
const httpsServer = https.createServer(credentials, app);
const port = process.env.PORT || 3000;
const server = httpsServer.listen(port);
参考 : https://www.jianshu.com/p/6e7760934315https://freessl.wosign.com/support/node-js-ssl.html