nodeJS使用阿里云免费SSL证书简例

环境:Debian 8,阿里云公共镜像。

步骤:

1.安装 nodejs

2.编辑 app.js 文件,内容如下:

var https = require('https');
var fs = require('fs');
var options = {
  key: fs.readFileSync('213949634960268.key'),
  cert: fs.readFileSync('213949634960268.pem')
};
var a = https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(443);

3.将从阿里云证书服务下载的文件,213949634960268.key 和 213949634960268.pem 上传到与 web.js 同一个路径中

4.运行(本例以root身份运行,图简单)

nodejs web.js

5.在火狐浏览器访问测试,https内容显示正常

nodeJS使用阿里云免费SSL证书简例_第1张图片

你可能感兴趣的:(nodejs,阿里云,ssl,node.js)