您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:将自定义域添加到 Azure CDN 终结点Tutorial: Add a custom domain to your Azure CDN endpoint

本教程介绍如何将自定义域添加到 Azure 内容分发网络 (CDN) 终结点。This tutorial shows how to add a custom domain to an Azure Content Delivery Network (CDN) endpoint. 使用 CDN 终结点来交付内容时,如果希望自己的域名在 CDN URL 中可见,则必须使用自定义域。When you use a CDN endpoint to deliver content, a custom domain is necessary if you would like your own domain name to be visible in your CDN URL. 使用可见的域名可以方便客户,适用于推广品牌。Having a visible domain name can be convenient for your customers and useful for branding purposes.

在配置文件中创建 CDN 终结点以后,终结点名称(azureedge.net 的子域)就会默认包括在用于交付 CDN 内容的 URL(例如 https://contoso.azureedge.net/photo.png)中。After you create a CDN endpoint in your profile, the endpoint name, which is a subdomain of azureedge.net, is included in the URL for delivering CDN content by default (for example, https://contoso.azureedge.net/photo.png). 为方便起见,Azure CDN 提供了用于将自定义域与 CDN 终结点相关联的选项。For your convenience, Azure CDN provides the option of associating a custom domain with a CDN endpoint. 使用此选项时,请在 URL 中使用自定义域而不是终结点名称来交付内容(例如,https://www.contoso.com/photo.png)。With this option, you deliver your content with a custom domain in your URL instead of an endpoint name (for example, https://www.contoso.com/photo.png).

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 创建 CNAME DNS 记录。Create a CNAME DNS record.
  • 将自定义域与 CDN 终结点相关联。Associate the custom domain with your CDN endpoint.
  • 验证自定义域。Verify the custom domain.

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

先决条件Prerequisites

在完成本教程中的步骤之前,必须先创建一个 CDN 配置文件,一个至少一个 CDN 终结点。Before you can complete the steps in this tutorial, you must first create a CDN profile and at least one CDN endpoint. 有关详细信息,请参阅快速入门:创建 Azure CDN 配置文件和终结点For more information, see Quickstart: Create an Azure CDN profile and endpoint.

如果没有自定义域,则必须先在域提供商那里购买一个。If you do not already have a custom domain, you must first purchase one with a domain provider. 有关示例,请参阅购买自定义域名For example, see Buy a custom domain name.

如果使用 Azure 来托管 DNS 域,必须将域提供商的域名系统 (DNS) 委托给 Azure DNS。If you are using Azure to host your DNS domains, you must delegate the domain provider's domain name system (DNS) to an Azure DNS. 有关详细信息,请参阅 向 Azure DNS 委派域For more information, see Delegate a domain to Azure DNS. 否则,如果通过域提供商处理 DNS 域,请转到创建 CNAME DNS 记录Otherwise, if you are using a domain provider to handle your DNS domain, proceed to Create a CNAME DNS record.

创建 CNAME DNS 记录Create a CNAME DNS record

在将自定义域与 Azure CDN 终结点结合使用之前,必须先在域提供商的配合下创建一个规范名称 (CNAME) 记录,使之指向 CDN 终结点。Before you can use a custom domain with an Azure CDN endpoint, you must first create a canonical name (CNAME) record with your domain provider to point to your CDN endpoint. CNAME 记录是一种 DNS 记录,用于将源域名映射到目标域名。A CNAME record is a type of DNS record that maps a source domain name to a destination domain name. 就 Azure CDN 来说,源域名是自定义域名,目标域名是 CDN 终结点主机名。For Azure CDN, the source domain name is your custom domain name and the destination domain name is your CDN endpoint hostname. 在 Azure CDN 验证已创建的 CNAME 记录以后,目标为源自定义域(例如 www.contoso.com)的流量就会路由到指定的目标 CDN 终结点主机名(例如 contoso.azureedge.net)。After Azure CDN verifies the CNAME record that you create, traffic addressed to the source custom domain (such as www.contoso.com) is routed to the specified destination CDN endpoint hostname (such as contoso.azureedge.net).

一个自定义域及其子域一次只能与一个终结点相关联。A custom domain and its subdomain can be associated with only a single endpoint at a time. 但是,可以通过使用多个 CNAME 记录,将同一自定义域中的不同子域用于不同的 Azure 服务终结点。However, you can use different subdomains from the same custom domain for different Azure service endpoints by using multiple CNAME records. 还可以将包含不同子域的自定义域映射到同一 CDN 终结点。You can also map a custom domain with different subdomains to the same CDN endpoint.

备注

如果使用 Azure DNS 作为域提供商,则任何别名记录类型都可以用于自定义域。Any alias record type can be used for Custom domains if you're using Azure DNS as your domain provider. 本演练使用 CNAME 记录类型。This walkthrough uses the CNAME record type. 如果使用 A 或 AAAA 记录类型,请遵循以下相同步骤,并将 CNAME 替换为所选的记录类型。If you're using A or AAAA record types, follow the same steps below and replace CNAME with the record type of your choice. 如果使用别名记录将根域添加为自定义域,并且要启用 SSL,则必须使用手动验证,如本文所述。If you're using an alias record to add a root domain as a custom domain and you want to enable SSL, you must use manual validation as described in this article. 有关详细信息,请参阅指向 Azure CDN 终结点的区域顶点For more information, see Point zone apex to Azure CDN endpoints.

映射临时的 cdnverify 子域Map the temporary cdnverify subdomain

映射现有的生产环境中的域时,有一些特殊注意事项。When you map an existing domain that is in production, there are special considerations. 在 Azure 门户中注册自定义域时,该域可能会出现短暂的停机现象。While you are registering your custom domain in the Azure portal, a brief period of downtime for the domain can occur. 为了避免 Web 流量中断,请先将自定义域映射到包含 Azure cdnverify 子域的 CDN 终结点主机名,以便创建临时的 CNAME 映射。To avoid interruption of web traffic, first map your custom domain to your CDN endpoint hostname with the Azure cdnverify subdomain to create a temporary CNAME mapping. 使用此方法,用户可以在进行 DNS 映射时访问域,不会出现中断现象。With this method, users can access your domain without interruption while the DNS mapping occurs.

否则,如果你是第一次使用自定义域,其上没有生产流量在运行,则可直接将自定义域映射到 CDN 终结点。Otherwise, if you are using your custom domain for the first time and no production traffic is running on it, you can directly map your custom domain to your CDN endpoint. 前进到映射永久自定义域Proceed to Map the permanent custom domain.

若要使用 cdnverify 子域创建 CNAME 记录,请执行以下操作:To create a CNAME record with the cdnverify subdomain:

  1. 登录到你的自定义域的域提供商的网站。Sign in to the web site of the domain provider for your custom domain.

  2. 查阅提供商的文档,或者在网站中搜索标有“域名”、“DNS”或“名称服务器管理”的区域,找到用于管理 DNS 记录的页面。 Find the page for managing DNS records by consulting the provider's documentation or searching for areas of the web site labeled Domain Name, DNS, or Name server management.

  3. 为自定义域创建一个 CNAME 记录条目并完成各个字段,如下表所示(字段名称可能有所不同):Create a CNAME record entry for your custom domain and complete the fields as shown in the following table (field names may vary):

    Source TypeType 目标Destination
    cdnverify.www.contoso.comcdnverify.www.contoso.com CNAMECNAME cdnverify.contoso.azureedge.netcdnverify.contoso.azureedge.net
    • 源:采用 cdnverify.<> 格式输入自定义域名,包括 cdnverify 子域。Source: Enter your custom domain name, including the cdnverify subdomain, in the following format: cdnverify.<custom domain name>. 例如,cdnverify.www.contoso.com。For example, cdnverify.www.contoso.com.

    • 键入:输入 CNAMEType: Enter CNAME.

    • 目标:采用 cdnverify. <终结点名称>.azureedge.net 格式输入 CDN 终结点主机名,包括 cdnverify 子域。Destination: Enter your CDN endpoint hostname, including the cdnverify subdomain, in the following format: cdnverify.<endpoint name>.azureedge.net. 例如,cdnverify.contoso.azureedge.net。For example, cdnverify.contoso.azureedge.net.

  4. 保存所做更改。Save your changes.

例如,GoDaddy 域注册机构的过程如下:For example, the procedure for the GoDaddy domain registrar is as follows:

  1. 登录后选择要使用的自定义域。Sign in and select the custom domain you want to use.

  2. 在“域”部分选择“管理所有项”,然后选择 “DNS” | “管理区域”。In the Domains section, select Manage All, then select DNS | Manage Zones.

  3. 对于“域名”, 请输入自定义域,然后选择“搜索”。 For Domain Name, enter your custom domain, then select Search.

  4. 在“DNS 管理” 页中选择“添加” ,然后在“类型”列表中选择“CNAME” 。From the DNS Management page, select Add, then select CNAME in the Type list.

  5. 完成 CNAME 条目的以下字段:Complete the following fields of the CNAME entry:

    CNAME 条目

    • 键入:让“CNAME” 保留选中状态。Type: Leave CNAME selected.

    • 主机:输入要使用的自定义域的子域,包括 cdnverify 子域名称。Host: Enter the subdomain of your custom domain to use, including the cdnverify subdomain name. 例如,cdnverify.www。For example, cdnverify.www.

    • 指向:输入 CDN 终结点的主机名,包括 cdnverify 子域名称。Points to: Enter the host name of your CDN endpoint, including the cdnverify subdomain name. 例如,cdnverify.contoso.azureedge.net。For example, cdnverify.contoso.azureedge.net.

    • TTL:让“1 小时”保留选中状态。 TTL: Leave 1 Hour selected.

  6. 选择“保存”。 Select Save.

    此时会将 CNAME 条目添加到 DNS 记录表。The CNAME entry is added to the DNS records table.

    DNS 记录表

将自定义域与 CDN 终结点相关联Associate the custom domain with your CDN endpoint

注册自定义域以后,即可将其添加到 CDN 终结点。After you've registered your custom domain, you can then add it to your CDN endpoint.

  1. 登录到 Azure 门户,浏览到 CDN 配置文件,其中包含需要映射到自定义域的终结点。Sign in to the Azure portal and browse to the CDN profile containing the endpoint that you want to map to a custom domain.

  2. 在“CDN 配置文件”页上,选择要与自定义域关联的 CDN 终结点。 On the CDN profile page, select the CDN endpoint to associate with the custom domain.

    此时会打开“终结点”页。 The Endpoint page opens.

  3. 选择“自定义域” 。Select Custom domain.

    CDN“自定义域”按钮

    此时会打开“添加自定义域” 页。The Add a custom domain page opens.

  4. 对于终结点主机名,用作 CNAME 记录的目标域的终结点主机名已预先填好,并源自 CDN 终结点 URL: <终结点主机名> .azureedge.net。For Endpoint hostname, the endpoint host name to use as the destination domain of your CNAME record is prefilled and is derived from your CDN endpoint URL: <endpoint hostname>.azureedge.net. 无法进行更改。It cannot be changed.

  5. 对于自定义主机名,请输入自定义域(包括子域),以用作 CNAME 记录的源域。For Custom hostname, enter your custom domain, including the subdomain, to use as the source domain of your CNAME record. 例如,www.contoso.com 或 cdn.contoso.com。For example, www.contoso.com or cdn.contoso.com. 请勿使用 cdnverify 子域名称。Do not use the cdnverify subdomain name.

    CDN“自定义域”对话框

  6. 选择 添加Select Add.

    Azure 会验证所输入的自定义域名是否存在 CNAME 记录。Azure verifies that the CNAME record exists for the custom domain name you entered. 如果该 CNAME 正确,会验证自定义域。If the CNAME is correct, your custom domain will be validated.

    新的自定义域设置传播到所有 CDN 边缘节点可能需要一些时间:It can take some time for the new custom domain settings to propagate to all CDN edge nodes:

    • 对于 Microsoft 推出的 Azure CDN 标准版配置文件,传播通常可在 10 分钟内完成。For Azure CDN Standard from Microsoft profiles, propagation usually completes in 10 minutes.
    • 对于 Akamai 的 Azure CDN 标准版配置文件,传播通常可在一分钟内完成。For Azure CDN Standard from Akamai profiles, propagation usually completes within one minute.
    • 对于“Verizon 提供的 Azure CDN 标准版” 和“Verizon 提供的 Azure CDN 高级版” 配置文件,传播通常在 10 分钟内完成。For Azure CDN Standard from Verizon and Azure CDN Premium from Verizon profiles, propagation usually completes in 10 minutes.

验证自定义域Verify the custom domain

完成自定义域的注册后,请验证该自定义域是否引用 CDN 终结点。After you have completed the registration of your custom domain, verify that the custom domain references your CDN endpoint.

  1. 确保在终结点缓存了公共内容。Ensure that you have public content that is cached at the endpoint. 例如,如果 CDN 终结点与某个存储帐户相关联,则 Azure CDN 会将内容缓存在公共容器中。For example, if your CDN endpoint is associated with a storage account, Azure CDN will cache the content in a public container. 若要测试自定义域,请验证容器是否已设置为允许公共访问,并至少包含一个文件。To test the custom domain, verify that your container is set to allow public access and contains at least one file.

  2. 在浏览器中,使用自定义域导航到文件的地址。In your browser, navigate to the address of the file by using the custom domain. 例如,如果自定义域为 www.contoso.com,则指向已缓存文件的 URL 应该类似于以下 URL:http://www.contoso.com/my-public-container/my-file.jpg。For example, if your custom domain is www.contoso.com, the URL to the cached file should be similar to the following URL: http://www.contoso.com/my-public-container/my-file.jpg. 验证结果是否与直接在 <终结点主机名> .azureedge.net 上访问 CDN 终结点时的结果相同。Verify that the result is that same as when you access the CDN endpoint directly at <endpoint hostname>.azureedge.net.

映射永久自定义域Map the permanent custom domain

如果已验证 cdnverify 子域已成功映射到终结点(或者如果使用的是不在生产环境中的新自定义域),则可将自定义域直接映射到 CDN 终结点主机名。If you have verified that the cdnverify subdomain has been successfully mapped to your endpoint (or if you are using a new custom domain that is not in production), you can then map the custom domain directly to your CDN endpoint hostname.

若要创建自定义域的 CNAME 记录,请执行以下操作:To create a CNAME record for your custom domain:

  1. 登录到你的自定义域的域提供商的网站。Sign in to the web site of the domain provider for your custom domain.

  2. 查阅提供商的文档,或者在网站中搜索标有“域名”、“DNS”或“名称服务器管理”的区域,找到用于管理 DNS 记录的页面。 Find the page for managing DNS records by consulting the provider's documentation or searching for areas of the web site labeled Domain Name, DNS, or Name Server Management.

  3. 为自定义域创建一个 CNAME 记录条目并完成各个字段,如下表所示(字段名称可能有所不同):Create a CNAME record entry for your custom domain and complete the fields as shown in the following table (field names may vary):

    Source TypeType 目标Destination
    <www.contoso.com><www.contoso.com> CNAMECNAME contoso.azureedge.netcontoso.azureedge.net
    • 源:输入自定义域名(例如 www.contoso.com)。Source: Enter your custom domain name (for example, www.contoso.com).

    • 键入:输入 CNAMEType: Enter CNAME.

    • 目标:输入 CDN 终结点主机名。Destination: Enter your CDN endpoint hostname. 必须采用 <endpoint name> .azureedge.net 格式,It must be in the following format:<endpoint name>.azureedge.net. 例如 contoso.azureedge.net。For example, contoso.azureedge.net.

  4. 保存所做更改。Save your changes.

  5. 如果此前已创建临时的 cdnverify 子域 CNAME 记录,请将其删除。If you're previously created a temporary cdnverify subdomain CNAME record, delete it.

  6. 如果是在生产环境中第一次使用此自定义域,请按将自定义域与 CDN 终结点相关联验证自定义域所述步骤进行操作。If you are using this custom domain in production for the first time, follow the steps for Associate the custom domain with your CDN endpoint and Verify the custom domain.

例如,GoDaddy 域注册机构的过程如下:For example, the procedure for the GoDaddy domain registrar is as follows:

  1. 登录后选择要使用的自定义域。Sign in and select the custom domain you want to use.

  2. 在“域”部分选择“管理所有项”,然后选择 “DNS” | “管理区域”。In the Domains section, select Manage All, then select DNS | Manage Zones.

  3. 对于“域名”, 请输入自定义域,然后选择“搜索”。 For Domain Name, enter your custom domain, then select Search.

  4. 在“DNS 管理” 页中选择“添加” ,然后在“类型”列表中选择“CNAME” 。From the DNS Management page, select Add, then select CNAME in the Type list.

  5. 完成 CNAME 条目的字段:Complete the fields of the CNAME entry:

    CNAME 条目

    • 键入:让“CNAME” 保留选中状态。Type: Leave CNAME selected.

    • 主机:输入要使用的自定义域的子域,Host: Enter the subdomain of your custom domain to use. 例如 www 或 cdn。For example, www or cdn.

    • 指向:输入 CDN 终结点的主机名,Points to: Enter the host name of your CDN endpoint. 例如 contoso.azureedge.net。For example, contoso.azureedge.net.

    • TTL:让“1 小时”保留选中状态。 TTL: Leave 1 Hour selected.

  6. 选择“保存”。 Select Save.

    此时会将 CNAME 条目添加到 DNS 记录表。The CNAME entry is added to the DNS records table.

    DNS 记录表

  7. 如果有一个 cdnverify CNAME 记录,请选择其旁边的铅笔图标,然后选择垃圾桶图标。If you have a cdnverify CNAME record, select the pencil icon next to it, then select the trash can icon.

  8. 选择“删除” ,以便删除 CNAME 记录。Select Delete to delete the CNAME record.

清理资源Clean up resources

在前述步骤中,已将自定义域添加到 CDN 终结点。In the preceding steps, you added a custom domain to a CDN endpoint. 如果不再需要将终结点与自定义域相关联,可通过以下步骤删除自定义域:If you no longer want to associate your endpoint with a custom domain, you can remove the custom domain by performing these steps:

  1. 在 CDN 配置文件中,选择其自定义域需要删除的终结点。In your CDN profile, select the endpoint with the custom domain that you want to remove.

  2. 在“终结点”页的“自定义域”下, 右键单击要删除的自定义域,然后从上下文菜单中选择“删除”。 From the Endpoint page, under Custom domains, right-click the custom domain that you want to remove, then select Delete from the context menu.

    自定义域于是与 CDN 终结点解除关联。The custom domain is disassociated from your endpoint.

后续步骤Next steps

本教程介绍了如何:In this tutorial, you learned how to:

  • 创建 CNAME DNS 记录。Create a CNAME DNS record.
  • 将自定义域与 CDN 终结点相关联。Associate the custom domain with your CDN endpoint.
  • 验证自定义域。Verify the custom domain.

转到下一教程,了解如何在 Azure CDN 自定义域上配置 HTTPS。Advance to the next tutorial to learn how to configure HTTPS on an Azure CDN custom domain.