【问题标题】:Node.js HTTPS Server Let's Encrypt Certificate Files Location on Windows ServerNode.js HTTPS 服务器让我们加密证书文件在 Windows 服务器上的位置
【发布时间】:2021-02-13 12:22:28
【问题描述】:

我有一个 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 文件生成吗?我还需要其他信息吗?有一些使用 with openssl 的示例,但似乎有所不同。

【问题讨论】:

    标签: node.js ssl lets-encrypt


    【解决方案1】:

    我打算从 let's encrypt 认证中获取 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 选项对象:

    const options = {
     key: fs.readFileSync('yourhomesite.com-key.pem', 'utf8'),
     cert: fs.readFileSync('yourhomesite.com-crt.pem', 'utf8')
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 2017-10-24
      • 2021-05-01
      • 1970-01-01
      • 2016-12-10
      • 2012-01-08
      • 2014-05-09
      相关资源
      最近更新 更多