Reputation: 497
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!!
Upvotes: 8
Views: 3081
Reputation: 1834
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
Upvotes: 13