一门APP开发教程
标题: ExpressJS 安装SSL证书 [打印本页]
作者: 陈家粉儿 时间: 2020-7-7 15:42
标题: ExpressJS 安装SSL证书
ExpressJS 安装ssl需要对编码有点基础,
购买证书后,下载nginx格式的证书 (解压后包含2个文件, key 私钥, cert 域名证书+根证书)
- //Test : curl -k https://localhost/
- var express = require('express');
- var https = require('https');
- var http = require('http');
- const fs = require('fs');
- const options = {
- key: fs.readFileSync('path/yourdomain.com.key'),
- cert: fs.readFileSync('path/yourdomain.com.crt')
- };
- var app = express();
- http.createServer(app).listen(80);
- https.createServer(options, app).listen(443);
复制代码
欢迎光临 一门APP开发教程 (https://bbs.yimenapp.com/) |
Powered by Discuz! X3.4 |