Reputation: 1666
I build my project in expressjs and I want to deploy it on a specific port. I deployed it and its working fine over my AWS EC2 instance (Ubuntu) but the issue is that it runs on HTTP, not HTTPS. So I research how we can run expressjs on HTTPS and the only way I found is given below:
var fs = require("fs"),
http = require("https");
var privateKey = fs.readFileSync('sslcert/server.key').toString();
var certificate = fs.readFileSync('sslcert/server.crt').toString();
var credentials = {key: privateKey, cert: certificate};
var server = http.createServer(credentials,function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(8000);
But the issue with this method is that it requiring cert and key files to enable HTTPS. I am using public ACM and AWS doesn't provide files for that. I tried another method using the library https://www.npmjs.com/package/express-sslify. It redirects my expressjs to HTTPS but it gives SSL error. SSL is already deployed on my website using AWS ACM public certificate and it's working fine. Kindly guide what steps I will be required to make my expressjs project compatible with AWS ACM.
Upvotes: 1
Views: 561
Reputation: 944387
See the documentation:
AWS Certificate Manager supports a growing number of AWS services. You cannot install your ACM certificate or your private ACM Private CA certificate directly on your AWS based website or application.
Put one of the supported services in front of your Express server instead. Elastic Load Balancer is probably the best option for you since you are using an EC2 instance rather than one of the more service oriented AWS features.
If you want to handle the SSL on your EC2 instance, then Amazon suggest using a third-party certificate authority.
Upvotes: 1