Search code examples
sslhttp-redirectamazon-elastic-beanstalkamazon-elb

Redirect http to https AWS Application Load Balancer


Hey everyone so I configured my ELB to use an SSL certificate and it works great, however, I still have a problem where if a user comes to my website on port 80 under HTTP the website does not redirect them to an HTTPS secure connection. Heres a screenshot of my ELB configuration as seen in the Elastic Beanstalk configuration tab. Any help is appreciated thank you. elb config


Solution

  • It wasn't the elb at all I simply had to add this code:

    if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "awsDevelopmentServer") {
      app.use(function(req, res, next) {
        // Insecure request?
        if (req.get("x-forwarded-proto") == "http") {
          // Redirect to https://
          return res.redirect("https://" + req.get("host") + req.url);
        }```