Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

javascript - Deploy Expressjs on AWS with Public ACM

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
');
});

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...