Node.JS Nginx Manager - Part III
This is the 3rd post of the series Nginx Manager npm package nginx-upstream. In this blog post, we will see how to define SSL configuration for our Nginx configuration file.
SSL termination is one of the best feature for reverse proxies like Nginx. Encryption and decryption processes are heavy CPU consuming jobs and to utilize our backend servers better, we definetly want to offload this operation to a load balancer. On the other hand, we even do not need to host our applications on https since our Nginx can redirect the request decrypted to our backend to our http port.
Below is the two methods to enable and disable SSL configuration.
So to enable certificate in a config file like below;
Use NginxUpstream as below;
Again first parameter refers to our host alias for upstreaming. Second parameter determines where to find our pem file for SSL in our nginx host. We can also define an upload mechanism for your certificate file, but this is out of scope of nginx-upstream since it is dealing with the Nginx config file only.
After executing addCertificate our config file would have 2 new lines and if config file contains return statement for non ssl sites (ie. return 444;), than this line would be removed to enable responding SSL port. An improvement for this method would be getting SSL Config section as a parameter and when adding certificate, adding those lines also.
See below our updated Nginx config file.
As you can already guess we can disable SSL for our Nginx with removeCertificate method. Usage is pretty straight forward;
So we have covered all existing method for NginxUpstream class. I will be adding more fancy functionality on this package for nginx configuration, so keep in touch by commenting below and thanks for reading this far.