-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to hot update the certificate and private key of the HTTPS server without restarting the server?The old ssl/tls certificate should be deleted. #2859
Comments
Look up |
After reading the source code, I found that when adding multiple ssl/tls certificates to the same domain name, the ones added later will not take effect, only the first one that meets the conditions will take effect. If the ssl/tls certificate expires, you need to replace the old one with a new one,The old ssl/tls certificate should be deleted. Using "addcontext" will not solve the problem because the old one will still be used. |
If "update" means "replace", the answer is "you can't for technical reasons" - there's no good way to tell when it's safe to stop using the old key+cert because of existing clients and sessions. See nodejs/node#15115 (comment) for an SNI-based solution and nodejs/node#15115 (comment) for why that won't always work. There are a bunch of workarounds but they all boil down to doing rolling restarts. |
This is the code I'm currently using. When the HTTPS key and/or certificate are overwritten while the server is running, this code will update them for the server without needing a reboot and without interrupting current connections: let timeout;
fs.watch(certFolder, (event, filename) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
httpsServer.setSecureContext({
key : fs.readFileSync(keyPath).toString(),
cert : fs.readFileSync(certPath).toString()
});
console.log('Secure context updated.');
}, 5000);
});
The reason the call to |
But for the case of using snicallback to select the certificate, this will not work properly. Because for the same domain name, snicallback will only be called once |
There has been no activity on this issue for 3 years and it may no longer be relevant. It will be closed 1 month after the last non-automated comment. |
There has been no activity on this issue and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. |
Is your feature request related to a problem? Please describe.
Please describe the problem you are trying to solve.
How to hot update the certificate and private key of the HTTPS server without restarting the server?
For example, whenever the ssl/tls certificate expires soon, how to replace the hostname certificate specified by the HTTPS server with the correct new one?
Describe the solution you'd like
Please describe the desired behavior.
Describe alternatives you've considered
Please describe alternative solutions or features you have considered.
The text was updated successfully, but these errors were encountered: