使用 HTTPS 将 example.at 路由到 S3 存储桶,将 *.example.at 路由到负载均衡器

Routing example.at to S3 bucket and *.example.at to load balancer with HTTPS

我已经设置了一个多租户应用程序,它应该可以通过子域(例如 https://client1.example.at). Requests to *.example.at are routed to a load balancer via Route 53. The load balancer has an AWS signed wildcard certificate (e.g. supporting example.at and *.example.at). From this side, everything is working as expected and I can access https://client1.example.at, https://client2.example.at 等)供客户端使用。

基于此设置,我想将没有子域(www 除外)的特定请求(例如 https://www.example.at or https://example.at 路由到存储桶(也称为 www.example.com)而不是负载均衡器(我只想为 "main domain") 的请求提供一个静态站点。它有效,但我只能在不使用 HTTPS 的情况下访问 www.example.at 和 example.at。我的设置如下所示:

然后我发现我必须使用 Cloudfront 才能将 HTTPS 用于带有 S3 存储桶的自定义域(如果正确的话?)。现在我有几个问题:

  1. 是否需要使用 Cloudfront 通过 HTTPS 为 www.example.at 和 example.at 提供我的 S3 存储桶中的内容?
  2. 如果需要 Cloudfront,那么我必须根据 official AWS docs 在美国东部地区为 www.example.at 和 example.at 申请新证书。是否可以使用 AWS 证书管理器为同一域创建两个证书,或者我是否会与此设置发生冲突?
  3. 是否可以使用 *.example.at 作为带有负载均衡器别名的类型记录?
  4. 一般来说,我的 Route 53 设置是否有效?

I wanted to route specific request without subdomain (except www) such as https://www.example.com or https://example.com to a bucket (which is also named www.example.com)

每个 "domains" 都必须路由到不同的存储桶,除非您在 S3 前面使用代理(重新路由从浏览器传递的主机名),域名必须与存储桶名称匹配。如果他们不这样做,那么您的请求将发送到与您从中路由的 DNS 名称匹配的存储桶,路由与 S3 存储桶端点的主机名无关。

换句话说,假设您的主机名是 www.example.com,并且您将 CNAME 设置为 example.com。s3.amazonaws.com(或者您可以使用网站端点,但它不会这个例子很重要)。

当请求到达 DNS 名称 www.example.com 时,它会被发送到 S3 主机名后面的 S3 服务器。来自浏览器的请求 是针对主机名 "www.example.com" 的,指向 S3 端点的实际 CNAME 引用是无关紧要的,因为 S3 永远不知道您的浏览器使用了什么实际 CNAME 来连接到 S3。因此 S3 将尝试从 www.example.com 存储桶中提取请求的对象。

URL -> S3 存储桶

It works but I can only access www.example.at and example.at without using HTTPS.

使用 SSL 到 S3 存储桶时,像这样的 CNAME DNS 路由不起作用。这样做的原因是 S3 通配符证书的深度为 1 级 (*.s3.amazonaws.com),因此您的存储桶 www.example.com.s3.amazonaws.com 将无法匹配它,因为它在上面有 2 个额外级别通配符。因此您的浏览器拒绝该证书,因为该证书对主机名无效。

要完成此操作,您必须在 S3 前面使用某种代理,并使用您自己的相关域证书。

Is it necessary to use Cloudfront to serve content from my S3 bucket for www.example.at and example.at via HTTPS?

CloudFront 是解决带有 CNAME 的 HTTPS 路由 DNS 到我们刚才提到的 S3 存储桶问题的绝佳选择。

If Cloudfront is necessary then I have to request a new certificate for www.example.at and example.at in region US EAST according to the official AWS docs. Is it possible to create two certificates for the same domain with AWS certificate manager or can I get some conflicts with this setup?

我无法回答这个问题,我只能建议您尝试找出会发生什么。如果它不起作用,那么它不是一个选择。弄清楚这一点应该不会花太多时间。

Is it ok to use *.example.at as A type record with alias to the load balancer at all?

澄清一下,A 记录只能是 IP 地址,A 别名类似于 CNAME(但特定于 Route53)。

我强烈推荐 CNAMES(或 ALIASES,它们很相似)。直接指向 S3 的 A-Records 之一不是一个好主意,因为您不知道该 IP 是否或何时会从服务中删除。通过使用 CNAME/ALIAS 引用主机名,您不必担心这一点。除非您可以 100% 确定 IP 将保持可用,否则您不应该引用它。

Generally speaking, is my Route 53 setup valid at all?

根据您的描述,我没有发现任何问题,听起来一切正常。

If Cloudfront is necessary then I have to request a new certificate for www.example.at and example.at in region US EAST according to the official AWS docs. Is it possible to create two certificates for the same domain with AWS certificate manager or can I get some conflicts with this setup?

正如@JoshuaBriefman 所建议的那样,我现在只是尝试为另一个地区的同一域创建另一个证书,并且成功了。我还可以将证书用于 CloudFront 分发(附加证书是在美国东部创建的)并且现在所有工作都没有任何问题。