繁体   English   中英

如何通过 AWS EC2 上的 HTTPS 为 nodeJS 应用程序提供服务?

[英]How to serve a nodeJS app via HTTPS on AWS EC2?

我正在尝试在 EC2 实例上运行一个 hello world express 应用程序并通过 HTTPS 为其提供服务。

这是服务器代码:

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!\n');
});
const server = app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

server.keepAliveTimeout = 65000; // Ensure all inactive connections are terminated by the ALB, by setting this a few seconds higher than the ALB idle timeout
server.headersTimeout = 66000; // Ensure the headersTimeout is set higher than the keepAliveTimeout due to this nodejs regression bug: https://github.com/nodejs/node/issues/27363

我创建了一个 EC2 实例并让它在那里运行。 此外,为了获得 HTTPS,我使用 SSL 证书启动了一个应用程序负载均衡器。 我在端口 443 上创建了一个侦听器,并将其转发到我的 EC2 上的端口 3000。 最后,我设置了一个 Route53 条目以指向该 ALB。

我得到的 24/7 是502 Bad Gateway 我在这里缺少一些基本的东西吗?

如何通过HTTPS运行最基本的快递服务器?

对于以后可能会偶然发现此问题的任何人:

If you wish to terminate HTTPS on the load balancer and speak HTTP to your app behind it you need to select HTTP as prototoll and the port of your node app when creating a target group in the console.

在此处输入图像描述

出于某种原因,我想了好几个小时,当我想接受 HTTPS 流量时,这应该是HTTPS443

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM