Node.js hosting with SSL?

Let's say I have a node.js app that hosts both HTTP and HTTPS server as described in the question: How to force SSL / https in Express.js

In my code, I have the following:

// General configuration settings for production usage
app.configure(function () {
  app.set('port', process.env.PORT || 3000);
  app.set('sslport', process.env.SSLPORT || 4000);
  ...
}

http.createServer(app).listen(app.get('port'), function () {
  winston.info('Express server listening on port ' + app.get('port'));
});

var options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options, app).listen(app.get('sslport'), function () {
  winston.info('Express server listening on port ' + app.get('sslport'));
});

      

Which works great for a local node server.

However, I want to publish my site to a cloud provider such as Azure websites, Heroku, Nodejitsu, etc.

All cloud nodes seem to set a value process.env.PORT

, but only one. When my HTTPS server is created, it usually crashes the application as the PORT is already in use by / access denied / etc.

So how do I create / host a site with a secure single port login page to work with ??

+3


source to share


1 answer


If you are using Heroku you get SSL without specifying a port in nodejs. All you need to do is listen to the heroportu PORT environment variable for HTTP requests. Once loaded into hero, you can access your heroku app using either https (on 443) or http (on port 80). Heroku is sent to your server.

Likewise, if you are using elastic load balancing with EC2, you can use SSL termination on the load balancer and redirect again to the node server listening on port 80 using http. http://aws.amazon.com/elasticloadbalancing



In both cases, you can use either self-signed or appropriate SSL certificates depending on your needs.

+7


source







All Articles