使用流量管理器集成在 Azure 应用服务中配置自定义域名Configure a custom domain name in Azure App Service with Traffic Manager integration

使用 Azure 流量管理器将流量负载均衡到 Azure 应用服务时,可以使用 <traffic-manager-endpoint>.trafficmanager.net 来访问应用服务应用。When you use Azure Traffic Manager to load balance traffic to Azure App Service, the App Service app can be accessed using <traffic-manager-endpoint>.trafficmanager.net. 还可以将自定义域名(例如 www.contoso.com)与应用服务应用相关联,为用户提供更易识别的域名。You can assign a custom domain name, such as www.contoso.com, with your App Service app in order to provide a more recognizable domain name for your users.

本文介绍如何使用与流量管理器集成的应用服务应用配置自定义域名。This article shows you how to configure a custom domain name with an App Service app that's integrated with Traffic Manager.

Note

使用流量管理器终结点配置域名时,仅支持 CNAME 记录。Only CNAME records are supported when you configure a domain name using the Traffic Manager endpoint. 由于不支持 A 记录,因此也不支持根域映射,例如 contoso.com。Because A records are not supported, a root domain mapping, such as contoso.com is also not supported.

准备应用Prepare the app

若要将自定义 DNS 名称映射到与 Azure 流量管理器集成的应用,Web 应用的应用服务计划必须位于“标准”层或更高层。To map a custom DNS name to an app that's integrated with Azure Traffic Manager, the web app's App Service plan must be in Standard tier or higher. 在此步骤中,需确保应用服务计划位于受支持的定价层。In this step, you make sure that the App Service app is in the supported pricing tier.

检查定价层Check the pricing tier

Azure 门户中,搜索并选择“应用服务”。In the Azure portal, search for and select App Services.

在“应用服务”页上,选择 Azure 应用的名称。On the App Services page, select the name of your Azure app.

在门户中导航到 Azure 应用

在应用页面的左侧导航栏中,选择“纵向扩展(应用服务计划)”。In the left navigation of the app page, select Scale up (App Service plan).

扩展菜单

蓝色的框突出显示了应用的当前层。The app's current tier is highlighted by a blue border. 进行检查,确保应用处于“标准”层或更高层(“生产”或“隔离”类别中的任何层)。Check to make sure that the app is in Standard tier or above (any tier in the Production or Isolated category). 如果是,请关闭“纵向扩展”页,跳到创建 CNAME 映射If yes, close the Scale up page and skip to Create the CNAME mapping.

检查定价层

扩展应用服务计划Scale up the App Service plan

如果需要纵向扩展应用,请选择“生产”类别中的任何定价层。If you need to scale up your app, select any of the pricing tiers in the Production category. 有关其他选项,请单击“查看其他选项”。For additional options, click See additional options.

单击“应用” 。Click Apply.

创建流量管理器终结点Create Traffic Manager endpoint

添加或删除终结点中的步骤操作,在流量管理器配置文件中将应用服务应用添加为终结点。Following the steps at Add or Delete Endpoints, add your App Service app as an endpoint in your Traffic Manager profile.

如果应用服务应用已处于受支持的定价层,则当你添加终结点时,它会显示在可用应用服务目标列表中。Once your App Service app is in a supported pricing tier, it shows up in the list of available App Service targets when you add the endpoint. 如果应用未列出,请验证应用的定价层If your app isn't listed, verify the pricing tier of your app.

创建 CNAME 映射Create the CNAME mapping

Note

可以使用 Azure DNS 为 Azure 应用服务配置自定义 DNS 名称。You can use Azure DNS to configure a custom DNS name for Azure App Service. 有关详细信息,请参阅使用 Azure DNS 为 Azure 服务提供自定义域设置For more information, see Use Azure DNS to provide custom domain settings for an Azure service.

请登录到域提供商的网站。Sign in to the website of your domain provider.

查找管理 DNS 记录的页面。Find the page for managing DNS records. 每个域提供商都有自己的 DNS 记录界面,因此请查阅提供商的文档。Every domain provider has its own DNS records interface, so consult the provider's documentation. 查找站点中标记为“域名”、“DNS”或“名称服务器管理”的区域。 Look for areas of the site labeled Domain Name, DNS, or Name Server Management.

通常通过查看帐户信息,然后查找如“我的域”之类的链接,便可以找到 DNS 记录页面 。Often, you can find the DNS records page by viewing your account information, and then looking for a link such as My domains. 转到该页面,然后查找名称类似于“区域文件”、“DNS 记录”或“高级配置”的链接 。Go to that page and then look for a link that is named something like Zone file, DNS Records, or Advanced configuration.

以下屏幕截图是 DNS 记录页的一个示例:The following screenshot is an example of a DNS records page:

示例 DNS 记录页

在示例屏幕截图中,选择“添加”以创建记录 。In the example screenshot, you select Add to create a record. 某些提供商提供了不同的链接来添加不同的记录类型。Some providers have different links to add different record types. 同样,请查阅提供商的文档。Again, consult the provider's documentation.

Note

对于某些提供商(例如 GoDaddy),在你选择单独的“保存更改”链接之前,这些 DNS 记录不会生效 。For certain providers, such as GoDaddy, changes to DNS records don't become effective until you select a separate Save Changes link.

虽然各个域提供商的具体情况不同,但你都需从非根自定义域名(例如 www.contoso.com)映射到与应用集成的流量管理器域名 (contoso.trafficmanager.cn)。While the specifics of each domain provider vary, you map from a non-root custom domain name (such as www.contoso.com) to the Traffic Manager domain name (contoso.trafficmanager.cn) that's integrated with your app.

Note

如果某条记录已被使用并且需要提前将应用绑定到该记录,可以创建其他 CNAME 记录。If a record is already in use and you need to preemptively bind your apps to it, you can create an additional CNAME record. 例如,若要提前将 www.contoso.cn 绑定到应用,请创建从 awverify.wwwcontoso.trafficmanager.cn 的 CNAME 记录。For example, to preemptively bind www.contoso.cn to your app, create a CNAME record from awverify.www to contoso.trafficmanager.cn. 然后可以将“www.contoso.cn”添加到应用,而无需更改“www”CNAME 记录。You can then add "www.contoso.cn" to your app without the need to change the "www" CNAME record. 有关详细信息,请参阅将活动 DNS 名称迁移到 Azure 应用服务For more information, see Migrate an active DNS name to Azure App Service.

在域提供商处添加或修改完 DNS 记录后,请保存这些更改。Once you have finished adding or modifying DNS records at your domain provider, save the changes.

根域的情况如何?What about root domains?

由于流量管理器只支持使用 CNAME 记录的自定义域映射,并且由于 DNS 标准不支持将 CNAME 记录用于映射根域(例如,contoso.com),流量管理器不支持到根域的映射。Since Traffic Manager only supports custom domain mapping with CNAME records, and because DNS standards don't support CNAME records for mapping root domains (for example, contoso.com), Traffic Manager doesn't support mapping to root domains. 若要暂时避开此问题,请从应用级别使用 URL 重定向。To work around this issue, use a URL redirect from at the app level. 例如,在 ASP.NET Core 中,可以使用 URL 重写In ASP.NET Core, for example, you can use URL Rewriting. 然后,使用流量管理器对子域 (www.contoso.com) 进行负载均衡。Then, use Traffic Manager to load balance the subdomain (www.contoso.com).

对于高可用性方案,可以通过创建多个从根域指向每个应用副本 IP 地址的“A 记录”,从而在不使用流量管理器的情况下实现容错 DNS 设置。For high availability scenarios, you can implement a fault-tolerant DNS setup without Traffic Manager by creating multiple A records that point from the root domain to each app copy's IP address. 然后,将同一根域映射到所有应用副本Then, map the same root domain to all the app copies. 由于同一域名无法映射到同一区域中的两个不同应用,此设置仅在应用副本位于不同区域时有效。Since the same domain name cannot be mapped to two different apps in the same region, this setup only works when your app copies are in different regions.

启用自定义域Enable custom domain

在域名称的记录传播完成后,使用浏览器验证自定义域名是否解析为应用服务应用。After the records for your domain name have propagated, use the browser to verify that your custom domain name resolves to your App Service app.

Note

CNAME 通过 DNS 系统向外传播可能需要一段时间。It can take some time for your CNAME to propagate through the DNS system. 可使用 https://www.digwebinterface.com/ 等服务验证该 CNAME 是否可用。You can use a service such as https://www.digwebinterface.com/ to verify that the CNAME is available.

  1. 域解析成功后,返回到 Azure 门户中的应用页面Once domain resolution succeeds, to back to your app page in the Azure Portal

  2. 在左侧导航栏中选择“自定义域” > “添加主机名”。 From the left navigation, select Custom domains > Add hostname.

  3. 键入之前映射的自定义域名,然后选择“验证”。Type the custom domain name that you mapped earlier and select Validate.

  4. 确保“主机名记录类型”设置为“CNAME (www.example.cn 或任何子域)”。Make sure that Hostname record type is set to CNAME (www.example.cn or any subdomain).

  5. 由于应用服务应用现已与流量管理器终结点集成,因此会在“CNAME 配置”下看到流量管理器域名。Since the App Service app is now integrated with a Traffic Manager endpoint, you should see the Traffic Manager domain name under CNAME configuration. 选择它,然后单击“添加自定义域”。Select it and click Add custom domain.

    将 DNS 名称添加到应用

后续步骤Next steps