添加letsencrypt证书到nodejs http服务器?
比方说,我有一个简单的nodejs http服务器,如下所述,还letsencrypt证书准备在/etc/letsencrypt
。 我如何去改变到https和添加证书?
var http = require('http'); var app = require('express')(); app.get('/', function (req, res) { res.send('Hello World!'); }); http.createServer(app).listen(3000, function () { console.log('Started!'); });
您需要使用https
模块。 这里是一个如何configuration你的服务器的例子:
const https = require('https'); const fs = require('fs'); function letsencryptOptions(domain) { const path = '/etc/letsencrypt/live/'; return { key: fs.readFileSync(path + domain + '/privkey.pem'), cert: fs.readFileSync(path + domain + '/cert.pem'), ca: fs.readFileSync(path + domain + '/chain.pem') }; } const options = letsencryptOptions('example.com'); https.createServer(options, function (req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000);
- 基于令牌的authentication(在Node.js中)
- 如何在NodeJS上使用S3 SSE C(服务器端encryption与客户端提供的密钥)
- mongoose如何处理密码编码很好?
- encryption通道的重新encryption会在Node.js中返回不同的encryption结果
- Android,PHP和node.js之间的encryption和解密
- crypto#randomBytes是如何随机的?
- 使用椭圆曲线键创build服务器和客户机时使用节点JS TLS密码和密码选项(不共享密码套件错误)
- 使用vb.net AES / CBCencryptionstring,并需要使用JavaScript CryptoJS进行解密
- Nodejsencryption与Python hashlib