本文介绍了我无法使用SNICallback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在createServer功能上使用SNICallback.当我尝试以下代码时,出现错误Missing PFX or certificate + pricate key.

I couldn't manage using SNICallback on createServerfunction.When I try the below codes I get an error as Missing PFX or certificate + pricate key.

我该如何解决这个问题?

How can I solve this issue?

var fs = require('fs'),
      tls = require('tls'),
      https = require('https');

var certs = {
    "safe.myDomain.com": {
        key: fs.readFileSync('../SSL/safe/private/key.pem'),
        cert: fs.readFileSync('../SSL/safe/certs/cert.pem') 
    },
    "api.myDomain.com": {
        key: fs.readFileSync('../SSL/api/private/key.pem'),
        cert: fs.readFileSync('../SSL/api/certs/cert.pem')   
    }
}

var httpsOptions = {
    SNICallback: function(hostname, cb) {
      var ctx = tls.createSecureContext(certs[hostname])
      cb(null, ctx])
    }
}

https.createServer(httpsOptions).listen(1443, function() {
    console.log('HTTPS server is listening on port 1443')
})

推荐答案

https.createServer的选项必须包含keycert,因为它们是必需的.即使SNI提供了主机名,也不会使用该设置.

The options to https.createServer must include key and cert as they are required. Even though that set won't be used if SNI provides a hostname.

请参见 tls.createServer ,其中根据需要将keycert标记为. (从 https.createServer 链接.)

See tls.createServer where it marks key and cert as required. (Linked from https.createServer.)

这篇关于我无法使用SNICallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:23