node.js - 为 Let's encrypt 设置 certbot 时选择哪个软件和系统?
问题描述
我在 U buntu Server 16.04 LTS (HVM)、SSD 卷类型 - ami-6a003c0f上运行的EC2实例上有一个节点应用程序,我想从Let's Encrypt with Certbot获得ssl证书。
在我的情况下设置Certbot时,我怀疑从列表中选择的正确软件和系统是什么?https://certbot.eff.org/
请帮我。
解决方案
对于 node.js,您需要在手动模式下运行letsencrypt,然后将证书添加到您的代码中。
以下命令将下载letsencrypt并生成您的证书。使用您的域名和电子邮件地址进行修改。
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto certonly --manual --email admin@example.com -d example.com
Letsencrypt 将创建一个包含四个文件的目录。在以下示例中,未使用文件 fullchain.pem。阅读文档以了解每个文件的详细信息。
位置:/etc/letsencrypt/live/example.com
注意:读取letsencrypt的输出以获取实际文件位置
示例 node.js:
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/example.com/chain.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8443);
使用网络浏览器测试https://example.com:8443/