在区域顶点托管负载均衡的 Azure Web 应用Host load-balanced Azure web apps at the zone apex

DNS 协议可防止分配区域顶点的 A 或 AAAA 记录之外的任何内容。The DNS protocol prevents the assignment of anything other than an A or AAAA record at the zone apex. contoso.com 是区域顶点的示例。An example zone apex is contoso.com. 这种限制将为流量管理器背后拥有负载均衡应用程序的应用程序所有者带来问题。This restriction presents a problem for application owners who have load-balanced applications behind Traffic Manager. 无法从区域顶点记录指向流量管理器配置文件。It isn't possible to point at the Traffic Manager profile from the zone apex record. 因此,应用程序所有者必须使用一种解决方法。As a result, application owners must use a workaround. 应用程序层的重定向必须从区域顶点重定向到另一个域。A redirect at the application layer must redirect from the zone apex to another domain. 例如,从 contoso.com 重定向到 www.contoso.com。An example is a redirect from contoso.com to www.contoso.com. 这种方案会给重定向功能带来单一故障点。This arrangement presents a single point of failure for the redirect function.

使用别名记录,此问题将不再存在。With alias records, this problem no longer exists. 应用程序所有者现在可将其区域顶点记录指向具有外部终结点的流量管理器配置文件。Now application owners can point their zone apex record to a Traffic Manager profile that has external endpoints. 应用程序所有者可以指向用于其 DNS 区域中任何其他域的相同流量管理器配置文件。Application owners can point to the same Traffic Manager profile that's used for any other domain within their DNS zone.

例如,contoso.com 和 www.contoso.com 可以指向同一流量管理器配置文件。For example, contoso.com and www.contoso.com can point to the same Traffic Manager profile. 只要流量管理器配置文件仅配置了外部终结点,就会出现这种情况。This is the case as long as the Traffic Manager profile has only external endpoints configured.

本文介绍如何为域顶点创建别名记录,以及为 Web 应用配置流量管理器配置文件终结点。In this article, you learn how to create an alias record for your domain apex, and configure your Traffic Manager profile end points for your web apps.

如果没有 Azure 订阅,可在开始前创建一个 1 元人民币试用帐户If you don't have an Azure subscription, create a 1rmb trial account before you begin.

必备条件Prerequisites

必须具有可用于在 Azure DNS 中托管以供测试的域名。You must have a domain name available that you can host in Azure DNS to test with. 必须能够完全控制此域。You must have full control of this domain. 完全控制包括能够为域设置名称服务器 (NS) 记录。Full control includes the ability to set the name server (NS) records for the domain.

有关在 Azure DNS 中托管域的说明,请参阅教程:在 Azure DNS 中托管域For instructions to host your domain in Azure DNS, see Tutorial: Host your domain in Azure DNS.

本教程中使用的示例域为 contoso.com,但请使用自己的域名。The example domain used for this tutorial is contoso.com, but use your own domain name.

创建资源组Create a resource group

创建一个资源组用于保存本文中使用的所有资源。Create a resource group to hold all the resources used in this article.

创建应用服务计划Create App Service plans

使用下表中的配置信息在该资源组中创建两个 Web 应用服务计划。Create two Web App Service plans in your resource group using the following table for configuration information. 有关创建应用服务计划的详细信息,请参阅在 Azure 中管理应用服务计划For more information about creating an App Service plan, see Manage an App Service plan in Azure.

名称Name 操作系统Operating System 位置Location 定价层Pricing Tier
ASP-01ASP-01 WindowsWindows 中国东部China East Dev/Test D1-SharedDev/Test D1-Shared
ASP-02ASP-02 WindowsWindows 中国北部China North Dev/Test D1-SharedDev/Test D1-Shared

创建应用服务Create App Services

创建两个 Web 应用,在每个应用服务计划中各创建一个。Create two web apps, one in each App Service plan.

  1. 在 Azure 门户页的左上角,选择“创建资源” 。On upper left corner of the Azure portal page, select Create a resource.

  2. 在搜索栏中键入“Web 应用”并按 Enter 键。 Type Web app in the search bar and press Enter.

  3. 选择“Web 应用”。 Select Web App.

  4. 选择“创建” 。Select Create.

  5. 接受默认值,并参考下表配置两个 Web 应用:Accept the defaults, and use the following table to configure the two web apps:

    名称Name
    (在 .chinacloudsites.cn 中必须是唯一的)(must be unique within .chinacloudsites.cn)
    资源组Resource Group 运行时堆栈Runtime stack 区域Region 应用服务计划/位置App Service Plan/Location
    App-01App-01 使用现有项Use existing
    选择你的资源组Select your resource group
    .NET Core 2.2.NET Core 2.2 中国东部China East ASP-01(D1)ASP-01(D1)
    App-02App-02 使用现有项Use existing
    选择你的资源组Select your resource group
    .NET Core 2.2.NET Core 2.2 中国北部China North ASP-02(D1)ASP-02(D1)

收集一些详细信息Gather some details

现在需要记下 Web 应用的 IP 地址和主机名。Now you need to note the IP address and host name for the web apps.

  1. 打开你的资源组,并选择你的第一个 Web 应用(在本示例中为 App-01)。Open your resource group and select your first web app (App-01 in this example).
  2. 在左栏中选择“属性”。 In the left column, select Properties.
  3. 记下“URL”下面的地址,并在“出站 IP 地址”下面,记下列表中的第一个 IP 地址。 Note the address under URL, and under Outbound IP Addresses note the first IP address in the list. 稍后在配置流量管理器终结点时,将要使用此信息。You'll use this information later when you configure your Traffic Manager end points.
  4. 针对 App-02 重复上述步骤。Repeat for App-02.

创建流量管理器配置文件Create a Traffic Manager profile

在资源组中创建流量管理器配置文件。Create a Traffic Manager profile in your resource group. 使用默认值,并键入在 trafficmanager.cn 命名空间中唯一的名称。Use the defaults and type a unique name within the trafficmanager.cn namespace.

有关创建流量管理器配置文件的信息,请参阅快速入门:为高度可用的 Web 应用程序创建流量管理器配置文件For information about creating a Traffic Manager profile, see Quickstart: Create a Traffic Manager profile for a highly available web application.

创建终结点Create endpoints

现在,可以创建两个 Web 应用的终结点。Now you can create the endpoints for the two web apps.

  1. 打开你的资源组,并选择你的流量管理器配置文件。Open your resource group and select your Traffic Manager profile.

  2. 在左栏中选择“终结点”。 In the left column, select Endpoints.

  3. 选择 添加Select Add.

  4. 参考下表配置终结点:Use the following table to configure the endpoints:

    类型Type 名称Name 目标Target 位置Location 自定义标头设置Custom Header settings
    外部终结点External endpoint End-01End-01 为 App-01 记下的 IP 地址IP address you recorded for App-01 中国东部China East 主机:<为 App-01 记下的 URL>host:<the URL you recorded for App-01>
    示例:host:app-01.chinacloudsites.cnExample: host:app-01.chinacloudsites.cn
    外部终结点External endpoint End-02End-02 为 App-02 记下的 IP 地址IP address you recorded for App-02 中国北部China North 主机:<为 App-02 记下的 URL>host:<the URL you recorded for App-02>
    示例:host:app-02.chinacloudsites.cnExample: host:app-02.chinacloudsites.cn

创建 DNS 区域Create DNS zone

可以使用现有 DNS 区域进行测试,或者创建新区域。You can either use an existing DNS zone for testing, or you can create a new zone. 若要在 Azure 中创建和委托新的 DNS 区域,请参阅教程:在 Azure DNS 中托管域To create and delegate a new DNS zone in Azure, see Tutorial: Host your domain in Azure DNS.

为自定义域验证添加 TXT 记录Add a TXT record for custom domain validation

将自定义主机名添加到 Web 应用时,它将查找特定的 TXT 记录来验证你的域。When you add a custom hostname to your web apps, it will look for a specific TXT record to validate your domain.

  1. 打开你的资源组并选择 DNS 区域。Open your resource group and select the DNS zone.

  2. 选择“记录集”。 Select Record set.

  3. 参考下表添加记录集。Add the record set using the following table. 对于值,请使用之前记录的实际 Web 应用 URL:For the value, use the actual web app URL that you previously recorded:

    名称Name 类型Type Value
    @ TXTTXT App-01.chinacloudsites.cnApp-01.chinacloudsites.cn

添加自定义域Add a custom domain

为两个 Web 应用添加自定义域。Add a custom domain for both web apps.

  1. 打开你的资源组,并选择你的第一个 Web 应用。Open your resource group and select your first web app.

  2. 在左栏中,选择“自定义域”。 In the left column, select Custom domains.

  3. 在“自定义域” 下,选择“添加自定义域” 。Under Custom Domains, select Add custom domain.

  4. 在“自定义域” 下,键入你的自定义域名。Under Custom domain, type your custom domain name. 例如 contoso.com。For example, contoso.com.

  5. 选择“验证”。 Select Validate.

    你的域应会通过验证,并在“主机名可用性”和“域所有权”旁边显示绿色的对号标记。 Your domain should pass validation and show green check marks next to Hostname availability and Domain ownership.

  6. 选择“添加自定义域” 。Select Add custom domain.

  7. 若要在“分配到站点的主机名”下面查看新主机名,请刷新浏览器。 To see the new hostname under Hostnames assigned to site, refresh your browser. 刷新页面不一定总能立即显示更改。The refresh on the page doesn't always show changes right away.

  8. 针对第二个 Web 应用重复上述过程。Repeat this procedure for your second web app.

添加别名记录集Add the alias record set

现在,请为区域顶点添加别名记录。Now add an alias record for the zone apex.

  1. 打开你的资源组并选择 DNS 区域。Open your resource group and select the DNS zone.

  2. 选择“记录集”。 Select Record set.

  3. 参考下表添加记录集:Add the record set using the following table:

    名称Name 类型Type 别名记录集Alias record set 别名类型Alias type Azure 资源Azure resource
    @ AA Yes Azure 资源Azure resource 流量管理器 - 你的配置文件Traffic Manager - your profile

测试 Web 应用Test your web apps

现在可以进行测试,以确保可以访问该 Web 应用,并且它可进行负载均衡。Now you can test to make sure you can reach your web app and that it's being load balanced.

  1. 打开 Web 浏览器并浏览到你的域。Open a web browser and browse to your domain. 例如 contoso.com。For example, contoso.com. 应会看到默认的 Web 应用页面。You should see the default web app page.
  2. 停止第一个 Web 应用。Stop your first web app.
  3. 关闭 Web 浏览器并等待几分钟。Close your web browser, and wait a few minutes.
  4. 启动 Web 浏览器并浏览到你的域。Start your web browser and browse to your domain. 看到的应该仍是默认 Web 应用页面。You should still see the default web app page.
  5. 停止第二个 Web 应用。Stop your second web app.
  6. 关闭 Web 浏览器并等待几分钟。Close your web browser, and wait a few minutes.
  7. 启动 Web 浏览器并浏览到你的域。Start your web browser and browse to your domain. 应会看到错误 403,指出 Web 应用已停止。You should see Error 403, indicating that the web app is stopped.
  8. 启动第二个 Web 应用。Start your second web app.
  9. 关闭 Web 浏览器并等待几分钟。Close your web browser, and wait a few minutes.
  10. 启动 Web 浏览器并浏览到你的域。Start your web browser and browse to your domain. 应会再次看到默认的 Web 应用页面。You should see the default web app page again.

后续步骤Next steps

若要详细了解别名记录,请参阅以下文章:To learn more about alias records, see the following articles:

若要了解如何迁移活动 DNS 名称,请参阅将活动 DNS 名称迁移到 Azure 应用服务To learn how to migrate an active DNS name, see Migrate an active DNS name to Azure App Service.