首页 > 解决方案 > SSL、Express、Nodejs:错误:错误:0909006C:PEM 例程:get_name:没有起始行

问题描述

我试图将证书添加到我的 nodeJs,Express 服务器,如下所示:

cert: fs.readFileSync('/path/to/private.key'),
key: fs.readFileSync('/path/to/your_domain_name.crt'),
ca: [
    fs.readFileSync('path/to/CA_root.crt'),
    fs.readFileSync('path/to/ca_bundle_certificate.crt')
]

我得到了这个错误

      c.context.setKey(key, passphrase);
                ^

Error: error:0909006C:PEM routines:get_name:no start line
    at Object.createSecureContext (_tls_common.js:151:17)
    at Server.setSecureContext (_tls_wrap.js:1155:27)
    at Server (_tls_wrap.js:1033:8)
    at new Server (https.js:65:14)
    at Object.createServer (https.js:89:10)
    at Object.<anonymous> (********)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
  library: 'PEM routines',
  function: 'get_name',
  reason: 'no start line',
  code: 'ERR_OSSL_PEM_NO_START_LINE'
}

请问有人遇到这个问题吗?

提前致谢

标签: node.jsexpressssl

解决方案


您可能在证书和密钥部分写入错误的文件名。key: 部分需要私钥文件名和 cert: 部分需要认证文件名。我在证书和密钥部分切换了您的文件名。

cert: fs.readFileSync('/path/to/your_domain_name.crt'),
key: fs.readFileSync('/path/to/private.key'),
ca: [
    fs.readFileSync('path/to/CA_root.crt'),
    fs.readFileSync('path/to/ca_bundle_certificate.crt')
]


推荐阅读