crypto.createCredentials()
está en desuso, por lo tanto, use tls.createSecureContext()
.
tls.createServer() deben tener key
y cert
en las opciones, porque se requieren en el manual. Tal vez tls.createServer()
utiliza estos parámetros como valores predeterminados en el caso SNICallback
no es compatible.
var secureContext = {
'mydomain.com': tls.createSecureContext({
key: fs.readFileSync('../path_to_key1.pem', 'utf8'),
cert: fs.readFileSync('../path_to_cert1.crt', 'utf8'),
ca: fs.readFileSync('../path_to_certificate_authority_bundle.ca-bundle1', 'utf8'), // this ca property is optional
}),
'myotherdomain.com': tls.createSecureContext({
key: fs.readFileSync('../path_to_key2.pem', 'utf8'),
cert: fs.readFileSync('../path_to_cert2.crt', 'utf8'),
ca: fs.readFileSync('../path_to_certificate_authority_bundle.ca-bundle2', 'utf8'), // this ca property is optional
}),
}
try {
var options = {
SNICallback: function (domain, cb) {
if (secureContext[domain]) {
if (cb) {
cb(null, secureContext[domain]);
} else {
// compatibility for older versions of node
return secureContext[domain];
}
} else {
throw new Error('No keys/certificates for domain requested');
}
},
// must list a default key and cert because required by tls.createServer()
key: fs.readFileSync('../path_to_key.pem'),
cert: fs.readFileSync('../path_to_cert.crt'),
}
https.createServer(options, function (req, res) {
res.end('Your dynamic SSL server worked!')
// Here you can put proxy server routing here to send the request
// to the application of your choosing, running on another port.
// node-http-proxy is a great npm package for this
}).listen(443);
} catch (err){
console.error(err.message);
console.error(err.stack);
}
Dentro del servidor puede utilizar nodejs paquete http-proxy para encaminar sus https solicitan a sus diversas aplicaciones.
Me gustaría una respuesta a esto también. Estoy planeando crear una aplicación Node.js que pueda alojar varios dominios con un certificado SSL para cada uno. Sería útil si podemos almacenar la información del certificado SSL en la base de datos. Entonces, una vez que detectamos el dominio del que provienen, podemos servir el contenido y el tema de su sitio. Sé que Node.js tiene una forma de definir un certificado SSL para cuando se inicia, pero no se sabe de una forma de hacerlo de forma dinámica en función del dominio en el que se encuentran. – Keverw
no estoy seguro, pero ¿no sería útil https://github.com/nodejitsu/node-http-proxy? –