[英]Running a simple HTTPS Node JS Server on Amazon EC2
我正在尝试在Amazon EC2上创建一个简单的https服务器来测试第三方API。
以下是我遵循的步骤:
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);
当我运行服务器,并尝试使用url https://ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com/连接到它时,我一直拒绝连接。
telnet测试还产生:
Trying XX.XXX.XXX.XXX...
telnet: connect to address XX.XXX.XXX.XXX: Connection refused
telnet: Unable to connect to remote host
有人可以告诉我在这个EC2实例上启用https需要修复的内容吗?
更改你的listen(8080)
以listen(443)
除非你有一个web服务器在443上监听并在8080上向节点发送请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.