使用流量管理器为 Azure 应用服务中的 Web 应用配置自定义域名Configuring a custom domain name for a web app in Azure App Service using Traffic Manager

使用 Azure 流量管理器对发往 Azure 网站的流量执行负载均衡时,可以使用 Azure 分配的 *.trafficmanager.cn 域名访问该网站。When you use a Azure Traffic Manager to load balance traffic to your Azure Website, that website can then be accessed using the *.trafficmanager.cn domain name assigned by Azure. 还可以将自定义域名(例如 www.contoso.com)与网站相关联,为用户提供更易识别的域名。You can also associate a custom domain name, such as www.contoso.com, with your website in order to provide a more recognizable domain name for your users.

本文提供了将自定义域名与一个应用服务应用配合使用的一般说明,该应用已与流量管理器集成以进行负载均衡。This article provides generic instructions for using a custom domain name with an App Service app that is integrated with Traffic Manager for load balancing.

如果没有流量管理器配置文件,请根据使用“快速创建”创建流量管理器配置文件中的信息创建一个。If you do not already have a Traffic Manager profile, use the information in Create a Traffic Manager profile using Quick Create to create one. 记下与流量管理器配置文件关联的 .trafficmanager.cn 域名,因为该域名会在本文档的后续步骤中使用。Note the .trafficmanager.cn domain name associated with your Traffic Manager profile, as this will be used later by later steps in this document.

本文适用于 Azure 应用服务(Web 应用、API 应用、移动应用和逻辑应用);对于云服务,请参阅为 Azure 云服务配置自定义域名This article is for Azure App Service (Web Apps, API Apps, Mobile Apps, Logic Apps); for Cloud Services, see Configuring a custom domain name for an Azure cloud service.


若应用由 Azure 流量管理器进行负载均衡,请单击本文顶部的选择器获取特定步骤。If your app is load-balanced by Azure Traffic Manager, click the selector at the top of this article to get specific steps.

自定义域名不能用于免费层Custom domain names are not enabled for Free tier. 必须向上缩放到更高定价层,这可能会改变订阅的计费量。You must scale up to a higher pricing tier, which may change how much you are billed for your subscription. 有关详细信息,请参阅应用服务定价See App Service Pricing for more information.

了解 DNS 记录Understanding DNS records

域名系统 (DNS) 用于在 Internet 上查找内容。The Domain Name System (DNS) is used to locate things on the internet. 例如,在浏览器中输入一个地址或单击网页上的某个链接时,它使用 DNS 将域转换为 IP 地址。For example, when you enter an address in your browser, or click a link on a web page, it uses DNS to translate the domain into an IP address. IP 地址有点像街道地址,但其用户友好性并不是很好。The IP address is sort of like a street address, but it's not very human friendly. 例如,记住 contoso.com 这样的 DNS 名称比较容易,而记住 或 2001:0:4137:1f67:24a2:3888:9cce:fea3 这样的 IP 地址则要困难得多。For example, it is much easier to remember a DNS name like contoso.com than it is to remember an IP address such as or 2001:0:4137:1f67:24a2:3888:9cce:fea3.

DNS 系统基于 记录The DNS system is based on records. 记录将特定的 名称(例如 contoso.com)与一个 IP 地址或其他的 DNS 名称相关联。Records associate a specific name, such as contoso.com, with either an IP address or another DNS name. 当某个应用程序(例如 Web 浏览器)在 DNS 中查找某个名称,它将找到该记录,并将它所指向的内容用作地址。When an application, such as a web browser, looks up a name in DNS, it finds the record, and uses whatever it points to as the address. 如果它所指向的值是 IP 地址,则浏览器会使用该值。If the value it points to is an IP address, the browser will use that value. 如果它指向另一个 DNS 名称,则应用程序必须再次执行解析。If it points to another DNS name, then the application has to do resolution again. 最终,所有名称解析都会以 IP 地址的形式结束。Ultimately, all name resolution will end in an IP address.

创建 Azure 网站时,DNS 名称自动分配到站点。When you create an Azure Website, a DNS name is automatically assigned to the site. 此名称采用 <yoursitename>.chinacloudsites.cn 的格式。This name takes the form of <yoursitename>.chinacloudsites.cn. 将网站添加为 Azure 流量管理器终结点时,将可以通过 <yourtrafficmanagerprofile>.trafficmanager.cn 域访问该网站。When you add your website as an Azure Traffic Manager endpoint, your website is then accessible through the <yourtrafficmanagerprofile>.trafficmanager.cn domain.


将网站配置为流量管理器终结点后,创建 DNS 记录时需使用 .trafficmanager.cn 地址。When your website is configured as a Traffic Manager endpoint, you will use the .trafficmanager.cn address when creating DNS records.

只能对流量管理器使用 CNAME 记录You can only use CNAME records with Traffic Manager

此外还有多种类型的记录,每种类型都有其自己的功能和限制,但是对于配置为流量管理器终结点的网站,我们只关心一种,即 CNAME 记录。There are also multiple types of records, each with their own functions and limitations, but for websites configured to as Traffic Manager endpoints, we only care about one; CNAME records.

CNAME 记录,或称别名记录CNAME or Alias record

CNAME 记录将特定的 DNS 名称(例如 mail.contoso.comwww.contoso.com)映射到另一个(规范)域名。A CNAME record maps a specific DNS name, such as mail.contoso.com or www.contoso.com, to another (canonical) domain name. 对于使用流量管理器的 Azure 网站,规范域名是流量管理器配置文件的 <myapp>.trafficmanager.cn 域名。In the case of Azure Websites using Traffic Manager, the canonical domain name is the <myapp>.trafficmanager.cn domain name of your Traffic Manager profile. 创建映射后,CNAME 为 <myapp>.trafficmanager.cn 域名创建一个别名。Once created, the CNAME creates an alias for the <myapp>.trafficmanager.cn domain name. CNAME 条目自动解析为 <myapp>.trafficmanager.cn 域名的 IP 地址,因此,如果网站的 IP 地址发生更改,则不需要采取任何操作。The CNAME entry will resolve to the IP address of your <myapp>.trafficmanager.cn domain name automatically, so if the IP address of the website changes, you do not have to take any action.

流量到达流量管理器后,后者会使用它为流量配置的负载均衡方法,将该流量路由到网站。Once traffic arrives at Traffic Manager, it then routes the traffic to your website, using the load balancing method it is configured for. 这对网站访问者完全透明。This is completely transparent to visitors to your website. 他们只会在浏览器中看到自定义域名。They will only see the custom domain name in their browser.


某些域注册机构只允许在使用 CNAME 记录(例如 www.contoso.com)时映射子域,而不允许在使用根名称(例如 contoso.com)时映射。Some domain registrars only allow you to map subdomains when using a CNAME record, such as www.contoso.com, and not root names, such as contoso.com. 有关 CNAME 记录的详细信息,请参阅由注册机构提供的文档、CNAME 记录上的 Wikipedia 条目IETF 域名 - 实现和规范文档。For more information on CNAME records, see the documentation provided by your registrar, the Wikipedia entry on CNAME record, or the IETF Domain Names - Implementation and Specification document.

将 Web 应用配置为标准模式Configure your web apps for standard mode

在与流量管理器集成的 Web 应用上设置自定义域名的功能仅适用于“标准”定价层。Setting a custom domain name on a web app that is integrated with Traffic Manager is only available for the Standard pricing tier.

若要深入了解应用服务定价层,包括如何更改应用的定价层,请参阅在 Azure 中纵向扩展应用For more information on the App Service pricing tiers, including how to change your app's pricing tier, see Scale up an app in Azure.

为自定义域添加 DNS 记录Add a DNS record for your custom domain

要将自定义域与 Azure 应用服务中的 Web 应用关联,必须在 DNS 表中为自定义域添加新条目。To associate your custom domain with a web app in Azure App Service, you must add a new entry in the DNS table for your custom domain. 请通过使用来自域提供商的管理工具执行此操作。You do this by using the management tools from your domain provider.


可以使用 Azure DNS 为 Azure Web 应用配置自定义 DNS 名称。You can use Azure DNS to configure a custom DNS name for your Azure Web Apps. 有关详细信息,请参阅使用 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.

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


如果某条记录已被使用并且需要提前将应用绑定到该记录,可以创建其他 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.com 绑定到 Web 应用,请创建从 awverify.wwwcontoso.trafficmanager.cn 的 CNAME 记录。For example, to preemptively bind www.contoso.com to your web app, create a CNAME record from awverify.www to contoso.trafficmanager.cn. 然后可以将“www.contoso.com”添加到 Web 应用,而无需更改“www”CNAME 记录。You can then add "www.contoso.com" to your Web App without changing the "www" CNAME record.

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

启用流量管理器Enable Traffic Manager

在传播域名记录后,应可使用浏览器验证自定义域名能否用于访问 Azure 应用服务中的 Web 应用。After the records for your domain name have propagated, you should be able to use your browser to verify that your custom domain name can be used to access your web app in Azure App Service.


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

如果尚未将 Web 应用添加为流量管理器终结点,必须在解析名称前执行此操作,因为自定义域名会路由到流量管理器。If you have not already added your web app as a Traffic Manager endpoint, you must do this before name resolution will work, as the custom domain name routes to Traffic Manager. 然后,流量管理器路由到 Web 应用。Traffic Manager then routes to your web app. 根据添加或删除终结点中的信息,在流量管理器配置文件中将 Web 应用添加为终结点。Use the information in Add or Delete Endpoints to add your web app as an endpoint in your Traffic Manager profile.


如果在添加终结点时 Web 应用未列出,请验证是否已将其配置为标准应用服务计划模式。If your web app is not listed when adding an endpoint, verify that it is configured for Standard App Service plan mode. 必须将 Web 应用设为标准模式才可使用流量管理器。You must use Standard mode for your web app in order to work with Traffic Manager.

  1. 在浏览器中,打开 Azure 门户In your browser, open the Azure Portal.

  2. 在“Web 应用”选项卡中,单击 Web 应用的名称,选择“设置”,并选择“自定义域”In the Web Apps tab, click the name of your web app, select Settings, and then select Custom domains

  3. 在“自定义域”边栏选项卡中,单击“添加主机名”。In the Custom domains blade, click Add hostname.

  4. 使用“主机名” 文本框输入要与此 Web 应用相关联的流量管理器域名。Use the Hostname text boxes to enter the Traffic Manager domain name to associate with this web app.

  5. 单击“验证” 以保存域名配置。Click Validate to save the domain name configuration.

  6. 单击“验证” 时,Azure 启动域验证工作流。Upon clicking Validate Azure will kick off Domain Verification workflow. 这会检查域的所有权和主机名的可用性,并报告成功或错误详情(附带如何解决错误的说明性指南)。This will check for Domain ownership as well as Hostname availability and report success or detailed error with prescriptive guidance on how to fix the error.

  7. 验证成功后,“添加主机名” 按钮变为激活状态,就可以分配主机名了。Upon successful validation Add hostname button will become active and you will be able to the assign hostname. 导航到浏览器中的自定义域名。Now navigate to your custom domain name in a browser. 现在应该会看到应用正在使用自定义域名运行。You should now see your app running using your custom domain name.

    完成配置后,自定义域名在 Web 应用的“域名” 部分列出。Once configuration has completed, the custom domain name will be listed in the domain names section of your web app.

此时,应可在浏览器中输入流量管理器域名,并查看它是否成功转至 Web 应用。At this point, you should be able to enter the Traffic Manager domain name in your browser and see that it successfully takes you to your web app.

后续步骤Next steps

有关详细信息,请参阅 Node.js 开发人员中心For more information, see the Node.js Developer Center.