Nodejs配置Https服务

1.选购阿里云SLL免费证书:链接

  
 
2.登录SSL控制台进行配置:链接

 
 

3.下载Nginx证书

 

4.下载了证书文件,将文件放在自己Node项目中的某个能读取的文件夹中,如 https 文件夹,然后编写nodejs代码:

let express = require("express");
let http = require("http");
//let https = require("https");
let fs = require("fs");
// Configuare https
const httpsOption = {
    key : fs.readFileSync("./https/6284770_searts.art.key"),
    cert: fs.readFileSync("./https/6284770_searts.art.pem")
}
// Create service
let app = express();
//http.createServer(app).listen(80);
https.createServer(httpsOption, app).listen(443);

5.运行,用 https:// 访问查看效果,至此,配置完成。
(0)

相关推荐