Running a Simple HTTPS Node JS Server on Amazon EC2

I am trying to create a simple https server on Amazon EC2 to test a third-party API.

Here are the steps I followed:

  • Created an instance of Amazon EC2 and opened HTTP and HTTPS ports:

enter image description here

  1. Simple ssl credentials created using

openssl genrsa 2048> privatekey.pem

openssl req -new -key privatekey.pem -out csr.pem

openssl x509 -req -days 365 -in csr.pem -signkey privatekey.pem -out server.crt

  1. Created a simple node js server
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);

When I start the server and try to connect to it using the url https://ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com/ , I continue to receive a connection denial.

The telnet test also creates:

Trying XX.XXX.XXX.XXX...
telnet: connect to address XX.XXX.XXX.XXX: Connection refused
telnet: Unable to connect to remote host

Can someone please tell me what I need to fix to enable https in this instance of EC2?

+4
1

listen(8080) listen(443), -, 443, node 8080.

+2

All Articles