I'm using Nginx to publish static content on port 80 and a 433 redirect (with SSL) to the NodeJS. The configuration of Nginx is as follows:
server {
listen 443 ssl;
ssl_certificate /opt/projetos/nodejs-project-ssl/vectortowns-cert.pem;
ssl_certificate_key /opt/projetos/nodejs-project-ssl/vectortowns-key.pem;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name 127.0.0.1:443;
location / {
proxy_pass https://127.0.0.1:8443;
proxy_redirect off;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
proxy_set_header X-Forwarded-Proto https;
}
}
With NodeJS, Express, and EJS, I'm publishing dynamic content to port 8443, also configured to use HTTPS. See the javascript code below (only the parts that are important for the question).
// other codes...
/* Enable https */
var privateKey = fs.readFileSync('/opt/projetos/nodejs-project-ssl/vectortowns-key.pem');
var certificate = fs.readFileSync('/opt/projetos/nodejs-project-ssl/vectortowns-cert.pem');
var credentials = {
key: privateKey,
cert: certificate
};
// other codes...
/* Controllers */
app.use(require('./controllers'));
https.createServer(credentials, app).listen(
configuration.server.port,
configuration.server.address,
function(){
logger.info('Server started: ' + configuration.server.address + ':' + configuration.server.port);
});
My questions are:
Thank you!!
To set up an HTTPS server, in your nginx. conf file include the ssl parameter to the listen directive in the server block, then specify the locations of the server certificate and private key files: server { listen 443 ssl; server_name www.example.com; ssl_certificate www. example.com.
To built an HTTPS server with nodeJs, we need an SSL (Secure Sockets Layer) certificate. We can create a self-signed SSL certificate on our local machine. Let's first create an SSL certificate on our machine first. After running this command, we would get some options to fill.
Fortunately, you can cache static content, reverse proxy and load balance among multiple application servers, and manage port contention between clients using Nginx. This makes Nginx an excellent tool for increasing Node. js performance.
To start your https server, run node app. js (here, app. js is name of the file) on the terminal. or in your browser, by going to https://localhost:8000 .
Use Nginx (and Nginx only) for SSL, that's the standard. As you set, Nginx works as a reverse proxy so it will feed you program with local unencrypted data for the given encrypted data on port 443, so it won't work if you also use SSL on your node program
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With