一门APP开发教程

标题: ExpressJS 安装SSL证书 [打印本页]

作者: 陈家粉儿    时间: 2020-7-7 15:42
标题: ExpressJS 安装SSL证书
ExpressJS 安装ssl需要对编码有点基础,
购买证书后,下载nginx格式的证书 (解压后包含2个文件,  key 私钥, cert 域名证书+根证书)

  1. //Test : curl -k https://localhost/

  2. var express = require('express');
  3. var https = require('https');
  4. var http = require('http');

  5. const fs = require('fs');

  6. const options = {
  7.   key: fs.readFileSync('path/yourdomain.com.key'),
  8.   cert: fs.readFileSync('path/yourdomain.com.crt')
  9. };

  10. var app = express();


  11. http.createServer(app).listen(80);
  12. https.createServer(options, app).listen(443);
复制代码







欢迎光临 一门APP开发教程 (https://bbs.yimenapp.com/) Powered by Discuz! X3.4