crypto.createCredentials()
बहिष्कृत है, इसलिए इसके बजाय tls.createSecureContext()
का उपयोग करें।
tls.createServer() विकल्पों में key
और cert
होना चाहिए, क्योंकि उन्हें मैन्युअल में आवश्यक है। शायद tls.createServer()
SNICallback
के मामले में डिफ़ॉल्ट के रूप में इन पैरामीटर का उपयोग करता है।
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);
}
सर्वर के अंदर आप मार्ग अपने https अपने विभिन्न अनुप्रयोगों के लिए अनुरोध करने के लिए पैकेज http-proxy NodeJS उपयोग कर सकते हैं।
मुझे इसका उत्तर भी चाहिए। मैं एक नोड.जेएस ऐप बनाने की योजना बना रहा हूं जो प्रत्येक के लिए एक एसएसएल प्रमाण पत्र के साथ एकाधिक डोमेन होस्ट कर सकता है। उपयोगी होगा अगर हम डीबी में एसएसएल प्रमाणपत्र जानकारी स्टोर कर सकते हैं। तो एक बार जब हम डोमेन का पता लगाते हैं तो वे आ रहे हैं, हम उनकी साइट विषय और सामग्री की सेवा कर सकते हैं। मुझे पता है कि Node.js के पास एसएसएल प्रमाण को परिभाषित करने का एक तरीका है, लेकिन यह उस डोमेन के आधार पर गतिशील रूप से करने के तरीके के बारे में नहीं जानता है। – Keverw
यकीन नहीं है, लेकिन https://github.com/nodejitsu/node-http-proxy सहायक नहीं होगा? –