Node.js 当我启用https时,站点停止工作

Node.js 当我启用https时,站点停止工作,node.js,ubuntu,ssl,https,ubuntu-14.04,Node.js,Ubuntu,Ssl,Https,Ubuntu 14.04,我是nodejs新手,我已经在nodejs上安装了ubuntu 我也有来自comodo的SSL证书 我遵循以下步骤 1) Login to root account and copy the key file in SSL cert to /etc/ssl/private/private.key file. 2) Then created file called /etc/ssl/certs/STAR_cert.com.crt and paste the contents of STAR_c

我是nodejs新手,我已经在nodejs上安装了ubuntu 我也有来自comodo的SSL证书

我遵循以下步骤

1) Login to root account and copy the key file in SSL cert to  /etc/ssl/private/private.key file.
2) Then created file called /etc/ssl/certs/STAR_cert.com.crt and paste  the contents of STAR_cert_com.crt into it.

3) Then create file called /etc/ssl/certs/AddTrustExternalCARoot.crt file and paste all the contents of three files present inside "CA and Intermediate Certs" folder.
之后,我将app.js文件配置为

var sslOptions = {
  key: fs.readFileSync('/etc/ssl/private/private.key'),
  cert: fs.readFileSync('/etc/ssl/certs/STAR_cert_com.crt'),
  requestCert: false,
  //ca: fs.readFileSync('/etc/ssl/certs/AddTrustExternalCARoot.crt'),
  rejectUnauthorized: false 
};

var secureServer = https.createServer(sslOptions,app).listen(443, function(){
   console.log("Express server listening on port : " + app.get('port'));
    console.log("Mode : " + app.get('mode'));
});

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
    res.end();
}).listen(80);
var secureServer = https.createServer(sslOptions,app).listen(443, function(){
   console.log("Express server listening on port : " + app.get('port'));
    console.log("Mode : " + app.get('mode'));
});
当我运行我的网站example.com时,它会重定向到,并给出以下错误信息

>     This webpage is not available
>     
>     DNS_PROBE_FINISHED_NXDOMAIN
但在服务器控制台上没有错误

如果我运行的网站没有https的网站工作良好

有什么想法吗


谢谢

您应该将sslOption json的密钥和证书参数作为字符串传递,例如,您可以使用express 4+轻松启动https nodejs服务器,如下所示:

 var fs = require('fs');
 var options = {
    key: fs.readFileSync('your.key').toString(),
    cert: fs.readFileSync('your_crt.crt').toString()
  };
  var https = require('https').Server(options,app);
  https.listen(config.port, function() {
    console.log('Server started successfully');
  });

希望有帮助

您似乎添加了密钥错误的证书。
仔细检查文件及其密钥对。如果你有中级证书,也包括这一点

使用服务器ip地址而不是域名是否会出现相同的错误?