使用 Azure DNS 为 Azure 服务提供自定义域设置Use Azure DNS to provide custom domain settings for an Azure service

Azure DNS 为支持自定义域或具有完全限定域名 (FQDN) 的任何 Azure 资源的自定义域提供 DNS。Azure DNS provides DNS for a custom domain for any of your Azure resources that support custom domains or that have a fully qualified domain name (FQDN). 一个例子就是,现已创建一个 Azure Web 应用,并希望用户通过将 contoso.com 或 www.contoso.com 用作 FQDN 来访问它。An example is you have an Azure web app and you want your users to access it by either using contoso.com, or www.contoso.com as an FQDN. 本文逐步讲解如何使用 Azure DNS 配置 Azure 服务,以便使用自定义域。This article walks you through configuring your Azure service with Azure DNS for using custom domains.

先决条件Prerequisites

若要对自定义域使用 Azure DNS,首先必须将该域委派给 Azure DNS。In order to use Azure DNS for your custom domain, you must first delegate your domain to Azure DNS. 有关如何为委派配置名称服务器的说明,请访问将域委派给 Azure DNSVisit Delegate a domain to Azure DNS for instructions on how to configure your name servers for delegation. 将域委派给 Azure DNS 区域后,便可以配置所需的 DNS 记录。Once your domain is delegated to your Azure DNS zone, you are able to configure the DNS records needed.

可为 Azure 函数应用公共 IP 地址应用服务(Web 应用)Blob 存储配置虚构域或自定义域。You can configure a vanity or custom domain for Azure Function Apps, Public IP addresses, App Service (Web Apps), and Blob storage.

Azure 函数应用Azure Function App

若要为 Azure 函数应用配置自定义域,需要创建一条 CNAME 记录,并在该函数应用本身上进行配置。To configure a custom domain for Azure function apps, a CNAME record is created as well as configuration on the function app itself.

导航到“函数应用”并选择自己的函数应用。Navigate to Function App and select your function app. 单击“平台功能”,并在“网络”下面单击“自定义域”。Click Platform features and under Networking click Custom domains.

函数应用边栏选项卡

记下“自定义域”边栏选项卡上的当前 URL,此地址用作创建的 DNS 记录的别名。Note the current url on the Custom domains blade, this address is used as the alias for the DNS record created.

自定义域边栏选项卡

导航到 DNS 区域,单击“+ 记录集”。Navigate to your DNS Zone and click + Record set. 在“添加记录集”边栏选项卡上填写以下信息,单击“确定”创建该记录集。Fill out the following information on the Add record set blade and click OK to create it.

属性Property Value 说明Description
NameName myfunctionappmyfunctionapp 此值连同域名标签是自定义域名的 FQDN。This value along with the domain name label is the FQDN for the custom domain name.
类型Type CNAMECNAME 使用 CNAME 记录相当于使用别名。Use a CNAME record is using an alias.
TTLTTL 11 1 表示 1 小时1 is used for 1 hour
TTL 单位TTL unit 小时Hours 小时用作时间计量单位Hours are used as the time measurement
别名Alias adatumfunction.chinacloudsites.cnadatumfunction.chinacloudsites.cn 为其创建别名的 DNS 名称,在本示例中,为默认提供给函数应用的 adatumfunction.chinacloudsites.cn DNS 名称。The DNS name you are creating the alias for, in this example it is the adatumfunction.chinacloudsites.cn DNS name provided by default to the function app.

导航回到函数应用,单击“平台功能”,在“网络”下面单击“自定义域”,在“自定义主机名”下面单击“+ 添加主机名”。Navigate back to your function app, click Platform features, and under Networking click Custom domains, then under Custom Hostnames click + Add hostname.

在“添加主机名”边栏选项卡上的“主机名”文本字段中输入 CNAME 记录,单击“验证”。On the Add hostname blade, enter the CNAME record in the hostname text field and click Validate. 如果找到该记录,则会出现“添加主机名”按钮。If the record is found, the Add hostname button appears. 单击“添加主机名”以添加该别名。Click Add hostname to add the alias.

函数应用添加主机名边栏选项卡

公共 IP 地址Public IP address

若要为使用公共 IP 地址资源(例如应用程序网关、负载均衡器、云服务、资源管理器 VM 和经典 VM)的服务配置自定义域,请使用 A 记录。To configure a custom domain for services that use a public IP address resource such as Application Gateway, Load Balancer, Cloud Service, Resource Manager VMs, and, Classic VMs, an A record is used.

导航到“网络” > “公共 IP 地址”,选择“公共 IP 资源”,单击“配置”。Navigate to Networking > Public IP address, select the Public IP resource and click Configuration. 记下显示的 IP 地址。Notate the IP address shown.

公共 IP 边栏选项卡

导航到 DNS 区域,单击“+ 记录集”。Navigate to your DNS Zone and click + Record set. 在“添加记录集”边栏选项卡上填写以下信息,单击“确定”创建该记录集。Fill out the following information on the Add record set blade and click OK to create it.

属性Property Value 说明Description
NameName mywebservermywebserver 此值连同域名标签是自定义域名的 FQDN。This value along with the domain name label is the FQDN for the custom domain name.
类型Type AA 由于资源是 IP 地址,因此应使用 A 记录。Use an A record as the resource is an IP address.
TTLTTL 11 1 表示 1 小时1 is used for 1 hour
TTL 单位TTL unit 小时Hours 小时用作时间计量单位Hours are used as the time measurement
IP 地址IP Address 公共 IP 地址。The public IP address.

创建 A 记录

创建 A 记录后,运行 nslookup 来验证记录解析。Once the A record is created, run nslookup to validate the record resolves.

公共 IP DNS 查找

应用服务(Web 应用)App Service (Web Apps)

下面逐步介绍如何配置应用服务 Web 应用的自定义域。The following steps take you through configuring a custom domain for an app service web app.

导航到“应用服务”,选择要配置自定义域名的资源,单击“自定义域”。Navigate to App Service and select the resource you are configuring a custom domain name, and click Custom domains.

记下“自定义域”边栏选项卡上的当前 URL,此地址用作创建的 DNS 记录的别名。Note the current url on the Custom domains blade, this address is used as the alias for the DNS record created.

自定义域边栏选项卡

导航到 DNS 区域,单击“+ 记录集”。Navigate to your DNS Zone and click + Record set. 在“添加记录集”边栏选项卡上填写以下信息,单击“确定”创建该记录集。Fill out the following information on the Add record set blade and click OK to create it.

属性Property Value 说明Description
NameName mywebservermywebserver 此值连同域名标签是自定义域名的 FQDN。This value along with the domain name label is the FQDN for the custom domain name.
类型Type CNAMECNAME 使用 CNAME 记录相当于使用别名。Use a CNAME record is using an alias. 如果资源使用了 IP 地址,则会使用 A 记录。If the resource used an IP address, an A record would be used.
TTLTTL 11 1 表示 1 小时1 is used for 1 hour
TTL 单位TTL unit 小时Hours 小时用作时间计量单位Hours are used as the time measurement
别名Alias webserver.chinacloudsites.cnwebserver.chinacloudsites.cn 为其创建别名的 DNS 名称,在本示例中,为默认提供给 Web 应用的 webserver.chinacloudsites.cn DNS 名称。The DNS name you are creating the alias for, in this example it is the webserver.chinacloudsites.cn DNS name provided by default to the web app.

创建 CNAME 记录

导航回到为自定义域名配置的应用服务。Navigate back to the app service that is configured for the custom domain name. 依次单击“自定义域”、“主机名”。Click Custom domains, then click Hostnames. 若要添加所创建的 CNAME 记录,请单击“+ 添加主机名”。To add the CNAME record you created, click + Add hostname.

图 1

完成此过程后,请运行 nslookup 来验证名称解析是否正常工作。Once the process is complete, run nslookup to validate name resolution is working.

图 1

若要详细了解如何将自定义域映射到应用服务,请访问将现有的自定义 DNS 名称映射到 Azure Web 应用To learn more about mapping a custom domain to App Service, visit Map an existing custom DNS name to Azure Web Apps.

Blob 存储Blob storage

下面逐步介绍如何使用 asverify 方法配置 Blob 存储帐户的 CNAME 记录。The following steps take you through configuring a CNAME record for a blob storage account using the asverify method. 此方法可确保不会造成停机。This method ensures there is no downtime.

导航到“存储” > “存储帐户”,选择自己的存储帐户,单击“自定义域”。Navigate to Storage > Storage Accounts, select your storage account, and click Custom domain. 记下步骤 2 中的 FQDN,此值用于创建第一条 CNAME 记录Notate the FQDN under step 2, this value is used to create the first CNAME record

Blob 存储自定义域

导航到 DNS 区域,单击“+ 记录集”。Navigate to your DNS Zone and click + Record set. 在“添加记录集”边栏选项卡上填写以下信息,单击“确定”创建该记录集。Fill out the following information on the Add record set blade and click OK to create it.

属性Property Value 说明Description
NameName asverify.mystorageaccountasverify.mystorageaccount 此值连同域名标签是自定义域名的 FQDN。This value along with the domain name label is the FQDN for the custom domain name.
类型Type CNAMECNAME 使用 CNAME 记录相当于使用别名。Use a CNAME record is using an alias.
TTLTTL 11 1 表示 1 小时1 is used for 1 hour
TTL 单位TTL unit 小时Hours 小时用作时间计量单位Hours are used as the time measurement
别名Alias asverify.adatumfunctiona9ed.blob.core.chinacloudapi.cnasverify.adatumfunctiona9ed.blob.core.chinacloudapi.cn 为其创建别名的 DNS 名称,在本示例中,为默认提供给存储帐户的 asverify.adatumfunctiona9ed.blob.core.chinacloudapi.cn DNS 名称。The DNS name you are creating the alias for, in this example it is the asverify.adatumfunctiona9ed.blob.core.chinacloudapi.cn DNS name provided by default to the storage account.

单击“存储” > “存储帐户”导航回到存储帐户,选择该存储帐户,单击“自定义域”。Navigate back to your storage account by clicking Storage > Storage Accounts, select your storage account and click Custom domain. 在文本框中键入创建的别名(不带 asverify 前缀),选中“使用间接 CNAME 验证”,单击“保存”。Type in the alias you created without the asverify prefix in the text box, check Use indirect CNAME validation, and click **Save. 完成此步骤后,返回 DNS 区域,并创建不带 asverify 前缀的 CNAME 记录。Once this step is complete, return to your DNS zone and create a CNAME record without the asverify prefix. 此后,可以安全删除带有 cdnverify 前缀的 CNAME 记录。After that point, you are safe to delete the CNAME record with the cdnverify prefix.

Blob 存储自定义域

运行 nslookup 验证 DNS 解析Validate DNS resolution by running nslookup

若要详细了解如何将自定义域映射到 Blob 存储终结点,请访问为 Blob 存储终结点配置自定义域名To learn more about mapping a custom domain to a blob storage endpoint visit Configure a custom domain name for your Blob storage endpoint

后续步骤Next steps

了解如何为 Azure 中托管的服务配置反向 DNSLearn how to configure reverse DNS for services hosted in Azure.