首页 > 解决方案 > 带有 Cloudflare CDN 的 Azure 流量管理器

问题描述

在我看来,我们有一个非常直接的要求,显然事实证明并非如此:

“根据用户的地理位置将用户重定向到相应的云区域,并使用 Cloudflare 作为域 mysubdomain.myparentdomain.com 的 CDN”

进一步简化它,使用美国云区域基础设施为来自美国的用户提供服务等。现在,我们选择了 Azure 流量管理器,因为它具有基于地理位置解析 DNS 的能力。

假设我们现在有两个云区域:

由于我们应该使用 Cloudflare 作为 CDN,因此这两个区域都在 Cloudflare DNS 中配置如下:

流量管理器现在配置了两个端点:

在我们的 DNS 注册商(Cloudflare 之外)中,我们添加了一条 DNS 记录来解析我们的服务 sa,如下所示:

**问题场景 1:**

1. 来自美国的用户在浏览器中输入 mysubdomain.myparentdomain.com
2. 浏览器解析到流量管理器记录
3. 流量管理器将其解析到美国端点
4. 美国端点由 Cloudflare 代理见上图。它已成功解析为 Cloudflare IP 地址。
5. 请求到达 Cloudflare,但主机标头仍然是 mysubdomain.myparentdomain.com
6. Cloudflare 尝试在其 DNS 中查找 mysubdomain.myparentdomain.com,但未找到任何内容。
7. Cloudflare 引发源 DNS 不可用的错误。

问题场景2:

为了解决问题 1,在 Cloudflare DNS 中创建 mysubdomain.myparentdomain.com DNS 记录,如下所示:

mysubdomain.myparentdomain.com 是 my-tm-profile.trafficmanager.net 的别名(实际服务指向流量管理器的 DNS 名称)

1. 来自美国的用户在浏览器中输入 mysubdomain.myparentdomain.com
2. 浏览器解析到流量管理器记录
3. 流量管理器将其解析到美国端点
4. 美国端点由 Cloudflare 代理,如上所示。它已成功解析为 Cloudflare IP 地址。
5. 请求到达 Cloudflare,但主机头仍然是 mysubdomain.myparentdomain.com
6. Cloudflare 尝试在其 DNS 中查找 mysubdomain.myparentdomain.com 并发现它再次指向流量管理器 DNS。
7. Cloudflare 进入尝试解析再次由 Cloudflare 代理的服务的循环。根据 Cloudflare 支持讨论,这是不可行的。

我无法看到如何使这成为可能。有什么建议吗?

标签: azurednscloudflareazure-traffic-manager

解决方案


I came here because I had a similar problem with Azure functions. My setup was like this:

  • Cloudflare subdomain.domain.com has cname to traffic manager domain
  • Traffic manager is setup with 2 endpoints
  • Each endpoint (azure function) has subdomain.domain.com setup as a custom domain, so when requests with this domain will come to functions, they will know how to handle requests properly. This is a little different from original question where there are sub domains behind the scenes, but for user that should not matter.

Problem was that once I was hitting subdomain.domain.com, I was getting azure functions 404 page. This hinted at problem that traffic manager was sending traffic to correct host, but host needs a domain name to be passed by traffic manager, so it can handle it properly. I archived that by specifying host header under custom headers in Azure Traffic Manager endpoints configuration in a format host:subdomain.domain.com. I just tried that same change with another project of mine without azure functions and it worked too (previously didn't). Hope that will help someone :)


推荐阅读