我有一台windows server 2012,想在https上运行一台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文件;我也没有这个文件。
这些其他的.pem文件可以在windows服务器上使用这个单一的pem文件来生成吗?我还需要其他信息吗?这里有一些使用openssl的例子,但看起来不一样。
发布于 2021-02-15 20:46:10
我打算使用“让我们加密证书”中的key.pem文件。现在我解决了这个问题。
First我使用win-acme工具在windows服务器上生成证书。要从证书生成过程中获取key.pem文件,需要在win-acme的settings.json文件中将PrivateKeyExportable修改为true。
其次是,你需要使用PEM编码文件(Apache,nginx等)使用win-acme来生成或续订证书。用于存储选项。选择“您想如何存储证书?”问题作为PEM编码文件(Apache、nginx等)。选项。
最后,您将在导出目录中同时拥有key.pem和crt.pem文件。然后将它们用于https选项对象,如下所示:
const options = {
key: fs.readFileSync('yourhomesite.com-key.pem', 'utf8'),
cert: fs.readFileSync('yourhomesite.com-crt.pem', 'utf8')
};https://stackoverflow.com/questions/66185037
复制相似问题