我给自己买了从证书颁发机构此文件:Node.js的HTTPS PEM错误:错误:0906D06C:PEM套路:PEM_read_bio:没有启动线
- domain.com.p7b
- domain.com.crt
- domain.com.ca束
我想这一点代码:
var express = require('express');
var app = express();
var fs = require("fs");
var https = require('https');
var privateKey = fs.readFileSync('domain.com.p7b').toString();
var certificate = fs.readFileSync('domain.com.crt').toString();
var ca_bundle = fs.readFileSync('domain.com.ca-bundle').toString();
var credentials = { key: privateKey,
ca : ca_bundle,
cert: certificate};
https.createServer(credentials,app).listen(8080, function() {
console.log('Example app listening on port 8080!');
});
启动脚本后,我得到以下错误:
(err): at Object.createSecureContext (_tls_common.js:87:19)
(err): at Server (_tls_wrap.js:721:25)
(err): at new Server (https.js:17:14)
(err): at Object.exports.createServer (https.js:37:10)
(err): at Object.<anonymous> (/utec_temp/https/web.js:27:7)
(err): at Module._compile (module.js:435:26)
(err): at Object.Module._extensions..js (module.js:442:10)
(err): at Module.load (module.js:356:32)
(err): at Function.Module._load (module.js:311:12)
(err): Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
(err): at Error (native)
(err): at Object.createSecureContext (_tls_common.js:87:19)
(err): at Server (_tls_wrap.js:721:25)
(err): at new Server (https.js:17:14)
(err): at Object.exports.createServer (https.js:37:10)
(err): at Object.<anonymous> (/utec_temp/https/web.js:27:7)
(err): at Module._compile (module.js:435:26)
(err): at Object.Module._extensions..js (module.js:442:10)
(err): at Module.load (module.js:356:32)
(err): at Function.Module._load (module.js:311:12)
,你可以在互联网上使用自签名证书谷歌大部分的例子,但是当我在一个真实的环境中工作发生了什么?
我少的代码开发工作与自签名密钥,如下面的例子:
https://stackoverflow.com/a/24283204/3957754
我研究,我发现这一点:
https://www.namecheap.com/support/knowledgebase/article.aspx/9705/0/nodejs
http://www.backwardcompatible.net/155-Setting-up-real-SSL-Nodejs-Express
Node.js https pem error: routines:PEM_read_bio:no start line
但我无法更正错误。
我也降低到一个文件:
var credentials = {cert: certificate};
和错误是一样的。所以我认为,也许从Windows到UNIX的格式错误。我使用dos2unix工具,错误是一样的。
我的节点版本是4.4.7
任何帮助表示赞赏。
提前致谢!
UPDATED
我在答案部分作品node.js的答案!但在一个优雅的或健康的方式,DONT修改您的应用代码,离开这个工作了Apache,Nginx的,HAProxy的或一些负载平衡器:
# apache 2.2 example
SSLCertificateFile /some/folder/certificate.crt
SSLCertificateKeyFile /some/folder/initial.key
SSLCertificateChainFile /some/folder/certificate.ca-bundle
这种复杂性必须是透明的开发团队和应由系统管理员,基础设施或与贵公司网络相关的其他团队管理。