I'm trying to create a simple https server on Amazon EC2 to test a third party API.
Here are the steps I've followed:
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
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 run the server, and attempt to connect to it using url https://ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com/, I keep getting a connection refused.
A telnet test also produces:
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 on this EC2 instance?
Change your listen(8080)
to listen(443)
unless you have a web server listening on 443 and sending request to node on 8080.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With