使用 EC2 实例的 AWS Application Load Balancer HTTP 到 HTTPS

AWS Aplication Load Balancer HTTP to HTTPS with EC2 instance

我在 Ubuntu 上有一个 EC2 实例 运行 一个 Node.Js 服务器。

我的目标是:

  1. 将我的托管区域连接到 EC2 实例
  2. 将所有传入流量从端口 80 路由到端口 3000(因为我的服务器在端口 3000 上运行)
  3. 最重要的是使用 Application Load Balancer 将所有请求转发到 HTTPS(我已经在证书管理器中创建了 SSL 证书)。

目前,我只能在端口 3000 (http://prntscr.com/livali). Https requests or Http to port 80 don't work (http://prntscr.com/livau2). Altought a made an A record on my hosted zone with the instances' Public Ip, it's not possible to open the instance via the hosted zone (http://prntscr.com/liv9no) 上使用 EC2 实例的 Public Ip 打开网站。

我真的很困惑,因为我不知何故无法解决这个问题 运行。如果能提供有关如何设置这一切的分步指南,我将不胜感激。

这些是 Web 服务器问题,而不是 DNS 问题。您需要设置诸如 NGINX 或 Apache 之类的东西来将端口 80 代理到端口 3000。有关信息,请参阅 Apache redirect to another port

您还可以在 Apache 中使用重写规则强制使用 HTTPS:https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

另一个强制使用 HTTPS 的选项是创建 CloudFront 分配并使用它。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-https.html

如果您已经拥有 SSL 证书,则仅使用端口 443 而不是端口 80 是安全的。

  1. 创建一个面向 Internet 的应用程序负载均衡器,它侦听端口 443 并将流量路由到端口 3000 上的 EC2 实例。

  2. 在通过 HTTP 访问您的域时将用户重定向到 HTTPS

    参见 Docs > Load Balancer Listeners > Redirect Actions

  3. 添加 A 记录以将您的域名指向负载均衡器的 public DNS。