title: How to serve a nodeJS app via HTTPS on AWS EC2?
body: <p>I'm trying to run a hello world express app on an EC2 instance and serve it via HTTPS. </p>
  
  <p>Here is the server code:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  
  app.get('/', function (req, res) {
    res.send('Hello World!\n');
  });
  const server = app.listen(3000, function () {
    console.log('Example app listening on port 3000!');
  });
  
  server.keepAliveTimeout = 65000; // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout
  server.headersTimeout = 66000; // Ensure the headersTimeout is set higher than the keepAliveTimeout due to this nodejs regression bug: https://github.com/nodejs/node/issues/27363
  </code></pre>
  
  <p>I created an EC2 instance and let it run there. Additionally to get HTTPS, I fired up an Application Load Balancer with an SSL certificate. I created a listener on port 443 and forwarded it to port 3000 on my EC2. Lastly I set up a Route53 entry to point to that ALB. </p>
  
  <p>All I get 24/7 is <code>502 Bad Gateway</code>. Am I missing something basic here? </p>
  
  <p>How to run the most basic express server via HTTPS?</p>