将活动 DNS 名称迁移到 Azure 应用服务Migrate an active DNS name to Azure App Service

本文介绍如何在不停机的情况下,将活动 DNS 名称迁移到 Azure 应用服务This article shows you how to migrate an active DNS name to Azure App Service without any downtime.

将实时站点及其 DNS 域名迁移到应用服务时,该 DNS 名称已在提供实时流量。When you migrate a live site and its DNS domain name to App Service, that DNS name is already serving live traffic. 可以在迁移期间提前将活动 DNS 名称绑定到应用服务应用,从而避免 DNS 解析中的停机时间。You can avoid downtime in DNS resolution during the migration by binding the active DNS name to your App Service app preemptively.

如果你不担心 DNS 解析中的停机时间,请参阅将现有的自定义 DNS 名称映射到 Azure 应用服务If you're not worried about downtime in DNS resolution, see Map an existing custom DNS name to Azure App Service.


若要完成本操作说明:To complete this how-to:

提前绑定域名Bind the domain name preemptively

提前绑定自定义域时,请先完成下面的两项操作,再对 DNS 记录进行更改:When you bind a custom domain preemptively, you accomplish both of the following before making any changes to your DNS records:

  • 验证域所有权Verify domain ownership
  • 为应用启用域名Enable the domain name for your app

最终将自定义 DNS 名称从旧站点迁移到应用服务应用时,DNS 解析中将不会有停机时间。When you finally migrate your custom DNS name from the old site to the App Service app, there will be no downtime in DNS resolution.

通过域提供商访问 DNS 记录Access DNS records with domain provider


可以使用 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.


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

创建域验证记录Create domain verification record

若要验证域所有权,请添加 TXT 记录。To verify domain ownership, Add a TXT record. TXT 记录从 awverify.<subdomain> 映射到 <appname>.chinacloudsites.cn。The TXT record maps from awverify.<subdomain> to <appname>.chinacloudsites.cn.

你需要的 TXT 记录取决于要迁移的 DNS 记录。The TXT record you need depends on the DNS record you want to migrate. 有关示例,请参阅下表(@ 通常表示根域):For examples, see the following table (@ typically represents the root domain):

DNS 记录示例DNS record example TXT 主机TXT Host TXT 值TXT Value
@(根)@ (root) awverifyawverify <appname>.chinacloudsites.cn<appname>.chinacloudsites.cn
www(子域)www (sub) awverify.wwwawverify.www <appname>.chinacloudsites.cn<appname>.chinacloudsites.cn
*(通配符)* (wildcard) awverify.*awverify.* <appname>.chinacloudsites.cn<appname>.chinacloudsites.cn

在 DNS 记录页中,记下要迁移的 DNS 名称的记录类型。In your DNS records page, note the record type of the DNS name you want to migrate. 应用服务支持来自 CNAME 和 A 记录的映射。App Service supports mappings from CNAME and A records.


对于某些提供程序(如 CloudFlare),awverify.* 不是有效记录。For certain providers, such as CloudFlare, awverify.* is not a valid record. 只能改用 *Use * only instead.


通配符 * 记录不会使用现有 CNAME 记录验证子域。Wildcard * records won't validate subdomains with an existing CNAME's record. 可能需要为每个子域显式创建一条 TXT 记录。You may need to explicitly create a TXT record for each subdomain.

启用应用的域Enable the domain for your app

Azure 门户中的应用页的左侧导航窗格中,选择“自定义域”。In the Azure portal, in the left navigation of the app page, select Custom domains.


在“自定义域”页中,选择“添加主机名”旁的 + 图标。In the Custom domains page, select the + icon next to Add hostname.


键入已添加 TXT 记录的完全限定的域名,如 www.contoso.comType the fully qualified domain name that you added the TXT record for, such as www.contoso.com. 对于通配符域(如 *.contoso.com),可以使用与通配符域匹配的任何 DNS 名称。For a wildcard domain (like *.contoso.com), you can use any DNS name that matches the wildcard domain.

选择“验证”。Select Validate.

“添加主机名”按钮会被激活。The Add hostname button is activated.

请确保“主机名记录类型”设置为你想要迁移的 DNS 记录类型。Make sure that Hostname record type is set to the DNS record type you want to migrate.

选择“添加主机名”。Select Add hostname.

将 DNS 名称添加到应用

新主机名可能需要经过一段时间后才会反映在应用的“自定义域”页中。It might take some time for the new hostname to be reflected in the app's Custom domains page. 请尝试刷新浏览器来更新数据。Try refreshing the browser to update the data.

已添加 CNAME 记录

你的自定义 DNS 名称现已在 Azure 应用中启用。Your custom DNS name is now enabled in your Azure app.

重新映射活动 DNS 名称Remap the active DNS name

唯一需要做的是重新映射活动 DNS 记录以指向应用服务。The only thing left to do is remapping your active DNS record to point to App Service. 现在,它仍然指向旧站点。Right now, it still points to your old site.

复制应用的 IP 地址(仅限 A 记录)Copy the app's IP address (A record only)

如果你要重新映射 CNAME 记录,请跳过此部分。If you are remapping a CNAME record, skip this section.

若要重新映射 A 记录,需要应用服务应用的外部 IP 地址,此地址显示在“自定义域”页中。To remap an A record, you need the App Service app's external IP address, which is shown in the Custom domains page.

通过选择右上角的 X 关闭“添加主机名”页。Close the Add hostname page by selecting X in the upper-right corner.

在“自定义域”页面中,复制应用的 IP 地址。In the Custom domains page, copy the app's IP address.

在门户中导航到 Azure 应用

更新 DNS 记录Update the DNS record

返回到域提供商的 DNS 记录页,选择要重新映射的 DNS 记录。Back in the DNS records page of your domain provider, select the DNS record to remap.

对于 contoso.com 根域示例,重新映射 A 或 CNAME 记录,如下表中的示例所示:For the contoso.com root domain example, remap the A or CNAME record like the examples in the following table:

FQDN 示例FQDN example 记录类型Record type 主机Host ValueValue
contoso.com (root)contoso.com (root) AA @ 通过复制应用的 IP 地址获得的 IP 地址IP address from Copy the app's IP address
www.contoso.com (sub)www.contoso.com (sub) CNAMECNAME www <appname>.chinacloudsites.cn<appname>.chinacloudsites.cn
*.contoso.com(通配符域)*.contoso.com (wildcard) CNAMECNAME * <appname>.chinacloudsites.cn<appname>.chinacloudsites.cn

保存设置。Save your settings.

在 DNS 传播发生后,DNS 查询应立即开始解析应用服务应用。DNS queries should start resolving to your App Service app immediately after DNS propagation happens.

Azure 中的活动域Active domain in Azure

可以在订阅之间或者在同一订阅内部迁移 Azure 中的活动自定义域。You can migrate an active custom domain in Azure, between subscriptions or within the same subscription. 但是,这种不停机的迁移方案需要在特定的时间为源应用和目标应用分配同一个自定义域。However, such a migration without downtime requires the source app and the target app are assigned the same custom domain at a certain time. 因此,需确保两个应用未部署到同一个部署单元(在内部称为“Web 空间”)。Therefore, you need to make sure that the two apps are not deployed to the same deployment unit (internally known as a webspace). 一个域名只能分配到每个部署单元中的一个应用。A domain name can be assigned to only one app in each deployment unit.

可以通过查看 FTP/S URL <deployment-unit>.ftp.chinacloudsites.chinacloudapi.cn 的域名,找到应用的部署单元。You can find the deployment unit for your app by looking at the domain name of the FTP/S URL <deployment-unit>.ftp.chinacloudsites.chinacloudapi.cn. 检查并确保源应用与目标应用的部署单元不同。Check and make sure the deployment unit is different between the source app and the target app. 应用的部署单元由它所在的应用服务计划决定。The deployment unit of an app is determined by the App Service plan it's in. 该部署单元是在创建计划时由 Azure 随机选择的,且无法更改。It's selected randomly by Azure when you create the plan and can't be changed. 在同一资源组和同一区域中创建两个计划时,Azure 只会确保这两个计划位于同一个部署单元,但不提供任何逻辑来确保计划位于不同的部署单元。Azure only makes sure two plans are in the same deployment unit when you create them in the same resource group and the same region, but it doesn't have any logic to make sure plans are in different deployment units. 在不同部署单元中创建计划的唯一方法是在新的资源组或区域中不断地创建计划,直到获得不同的部署单元。The only way for you to create a plan in a different deployment unit is to keep creating a plan in a new resource group or region until you get a different deployment unit.

后续步骤Next steps

了解如何将自定义 TLS/SSL 证书绑定到应用服务。Learn how to bind a custom TLS/SSL certificate to App Service.