Last active
August 5, 2016 05:45
-
-
Save Dev-Dipesh/aa9d6fbd62b6e824b4f25b64c0af7cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = restify.createServer(); | |
const https_server = restify.createServer({ | |
certificate: fs.readFileSync('certs/ca.crt'), | |
key: fs.readFileSync('certs/key.pem'), | |
name: 'Sellnews-Trends', | |
}, err => { | |
console.log(err, err.stack); | |
}); | |
const setup_server = function(server) { | |
server.get("/", (req, res, next) => { | |
res.writeHead(200, { | |
'Content-Type': 'application/json; charset=utf-8' | |
}); | |
res.end(JSON.stringify({"status": "Get req."})); | |
}); | |
} | |
// Now, setup both servers in one step | |
setup_server(server); | |
setup_server(https_server); | |
// Start our servers to listen on the appropriate ports | |
server.listen(6066, function () { | |
console.log("Server started @ 6066"); | |
}); | |
https_server.listen(4043, function () { | |
console.log("Server started @ 4043"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are lot of articles out there on the internet to explain how to setup https in a Node.JS app on EC2, but none of them are really well suited.
Above approach is one way, in which I'm setting servers for both
http
andhttps
and then using iptables to re-route the ports as bleowHowever, this isn't the best way to do this. Instead, setup and ELB in AWS for you instance and create a certificate in AWS CM (Certificate Manager). Use the certificate in CM while creating ELB, and in ELB use Load Balancer port
443
and Instance Port80
.Now in main app just run the app on any port and re-route it to port 80.
From above ELB get the DNS (A-record) name and save it in your Domain Provider CNAME records.
Voila! that's it you're done here.