w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to setup dual http and https servers behind a load balancer like elastic balancer
  1. Like you stated, you may configure the ELB to forward all HTTPS and HTTP traffic to your applications http server, eliminating the need to handle any https configuration in your application. You may refer to the 'X-Forwarded-Proto' header to detect whether the request is coming though as http vs https.

    For my use case, I forward all traffic to https, so I simply redirect if the the header type is http:

    app.use(req, res, next) {
      if(req.headers['x-forwarded-proto'] == 'http' &&
    process.env.NODE_ENV!=="development"){
        res.redirect('https://' + req.headers.host + req.path);
      } else {
        next();
      }
    }
    
  2. If you'd prefer to keep the cert in the App, then it would be as simple as leaving them somewhere in your app directory and loading them when you create the server, like this





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.