你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Azure CLI 创建 Azure 内容分发网络的配置文件和终结点

除了 Azure 门户方法外,你还可以使用下文中的示例 Azure CLI 脚本来管理以下内容分发网络操作:

  • 创建内容分发网络配置文件。
  • 创建内容分发网络终结点。
  • 创建内容分发网络源组并将其设为默认组。
  • 创建内容分发网络源。
  • 创建自定义域并启用 HTTPS。

先决条件

示例脚本

如果你还没有针对内容分发网络配置文件的资源组,请使用命令 az group create 创建一个:

# Create a resource group to use for the content delivery network.
az group create --name MyResourceGroup --location eastus

以下 Azure CLI 脚本将创建内容分发网络配置文件和内容分发网络终结点:

# Create a content delivery network profile.
az cdn profile create --resource-group MyResourceGroup --name MyCDNProfile --sku Standard_Microsoft

# Create a content delivery network endpoint.
az cdn endpoint create --resource-group MyResourceGroup --name MyCDNEndpoint --profile-name MyCDNProfile --origin www.contoso.com

以下 Azure CLI 脚本将创建内容分发网络源组、设置终结点的默认源组,并创建新的源:

# Create an origin group.
az cdn origin-group create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyOriginGroup --origins origin-0

# Make the origin group the default group of an endpoint.
az cdn endpoint update --resource-group MyResourceGroup --name MyCDNEndpoint --profile-name MyCDNProfile --default-origin-group MyOriginGroup

# Create another origin for an endpoint.
az cdn origin create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name origin-1 --host-name example.contoso.com

以下 Azure CLI 脚本将创建内容分发网络自定义域并启用 HTTPS。 必须先使用 Azure DNS 或 DNS 提供程序创建规范名称 (CNAME) 记录来指向你的内容分发网络终结点,才能将自定义域与 Azure 内容分发网络终结点相关联。 有关详细信息,请参阅创建 CNAME DNS 记录

# Associate a custom domain with an endpoint.
az cdn custom-domain create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyCustomDomain --hostname www.example.com

# Enable HTTPS on the custom domain.
az cdn custom-domain enable-https --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyCustomDomain

清理资源

完成运行示例脚本后,使用以下命令删除资源组以及与其关联的所有资源。

# Delete the resource group.
az group delete --name MyResourceGroup

本文中使用的 Azure CLI 命令