title: Running a simple HTTPS Node JS Server on Amazon EC2
body: <p>I'm trying to create a simple https server on Amazon EC2 to test a third party API. </p>
  
  <p>Here are the steps I've followed:</p>
  
  <ol>
  <li>Created an Amazon EC2 instance, and opened up HTTP and HTTPS ports:</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/aojDg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aojDg.png" alt="enter image description here"></a></p>
  
  <ol start="2">
  <li>Created simple ssl credentials using</li>
  </ol>
  
  <blockquote>
    <p>openssl genrsa 2048 > privatekey.pem</p>
    
    <p>openssl req -new -key privatekey.pem -out csr.pem</p>
    
    <p>openssl x509 -req -days 365 -in csr.pem -signkey privatekey.pem -out
    server.crt</p>
  </blockquote>
  
  <ol start="3">
  <li>Created a simple node js server</li>
  </ol>
  
  <blockquote>
  <pre><code>var https = require('https');
  var fs = require('fs');
  var options = {
    key: fs.readFileSync('./privatekey.pem'),
    cert: fs.readFileSync('./server.crt')
  };
  
  https.createServer(options, function (req, res) {
    res.writeHead(200);
    res.end("hello world\n");
  }).listen(8080);
  </code></pre>
  </blockquote>
  
  <p>When I run the server, and attempt to connect to it using url <a href="https://ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com/" rel="noreferrer">https://ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com/</a>, I keep getting a connection refused. </p>
  
  <p>A telnet test also produces:</p>
  
  <pre><code>Trying XX.XXX.XXX.XXX...
  telnet: connect to address XX.XXX.XXX.XXX: Connection refused
  telnet: Unable to connect to remote host
  </code></pre>
  
  <p>Can someone please tell me what I need to fix to enable https on this EC2 instance?</p>