[英]Node.js - Change the SSL certificate for an HTTPS server dynamically at runtime
[英]Node.js HTTPS Server Let's Encrypt Certificate Files Location on Windows Server
我有一個 windows 服務器 2012 並想在 Z5E056Z1500A1C807BADE7 上運行 node.js web 服務器我有讓我們加密的 SSL 證書。
我的服務器代碼在這里:
const https = require("https"),
fs = require("fs");
const options = {
key: // not have,
cert: "C:\\ProgramData\\win-acme\\acme-v02.api.letsencrypt.org\\Certificates\\ichangedthispart-csr.pem"
};
const express = require('express')
const qs=require('qs')
const app = express()
const port = 3000
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
https.createServer(options, app).listen(8080);
當我只使用 cert 選項運行時
node:_tls_common:155
context.setCert(cert);
^
Error: error:0909006C:PEM routines:get_name:no start line
at setCerts (node:_tls_common:155:13)
at Object.createSecureContext (node:_tls_common:210:7)
at Server.setSecureContext (node:_tls_wrap:1336:27)
at Server (node:_tls_wrap:1191:8)
at new Server (node:https:67:14)
at Object.createServer (node:https:92:10)
at Object.<anonymous> (C:\inetpub\wwwroot\app\server.js:42:7)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32) {
library: 'PEM routines',
function: 'get_name',
reason: 'no start line',
code: 'ERR_OSSL_PEM_NO_START_LINE'
}
我在 win-acme 目錄中沒有“key”的 pem 文件。 在某些示例中,還有另一個用於 'ca' 的 pem 文件; 我也沒有那個文件。
可以使用 windows 服務器上的單個 pem 文件生成這些 other.pem 文件嗎? 我還需要其他信息嗎? 有一些與 openssl 一起使用的示例,但似乎有所不同。
我打算從讓我們加密認證中獲得 key.pem 文件。 現在我解決了這個問題。
首先,我使用 win-acme 工具在 windows 服務器上生成證書。 要從證書生成過程中獲取 key.pem 文件,您需要在 win-acme 的 settings.json 文件中將 PrivateKeyExportable 更改為 true。
其次,您需要使用帶有 PEM 編碼文件(Apache、nginx 等)的 win-acme 生成或更新證書以用於存儲選項。 選擇“您希望如何存儲證書?” 問題作為 PEM 編碼文件(Apache、nginx 等)選項。
最后,您將在導出目錄中同時擁有 key.pem 和 crt.pem 文件。 然后將它們用於 https 選項 object 為:
const options = {
key: fs.readFileSync('yourhomesite.com-key.pem', 'utf8'),
cert: fs.readFileSync('yourhomesite.com-crt.pem', 'utf8')
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.