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); 

Was this helpful?

1 / 0