你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
重要说明
Microsoft Azure CDN Standard(经典版)将于 2027 年 9 月 30 日停用。 为了避免出现服务中断,请务必在 2027 年 9 月 30 日之前将 Microsoft 的 Azure CDN 标准层(经典版)配置文件迁移到 Azure Front Door 标准层或高级层。 有关详细信息,请参阅 Microsoft Azure CDN Standard(经典版)停用。
Edgio 的 Azure CDN 已于 2025 年 1 月 15 日停用。 有关详细信息,请参阅 Edgio Azure CDN 停用常见问题解答。
作为 Azure 门户的替代方法,可以使用这些示例 Azure CLI 脚本来管理以下内容分发网络作:
- 创建内容分发网络配置文件。
- 创建内容分发网络终结点。
- 创建内容分发网络源组并将其设为默认组。
- 创建内容分发网络源。
- 创建自定义域并启用 HTTPS。
先决条件
在 Azure Cloud Shell 中使用 Bash 环境。 有关详细信息,请参阅开始使用 Azure Cloud Shell。
如果要在本地运行 CLI 引用命令,请安装 Azure CLI。 如果在 Windows 或 macOS 上运行,请考虑在 Docker 容器中运行 Azure CLI。 有关详细信息,请参阅如何在 Docker 容器中运行 Azure CLI。
如果使用的是本地安装,请使用 az login 命令登录到 Azure CLI。 若要完成身份验证过程,请遵循终端中显示的步骤。 有关其他登录选项,请参阅 使用 Azure CLI 向 Azure 进行身份验证。
按照提示,请在首次使用时安装 Azure CLI 扩展。 有关扩展详细信息,请参阅使用和管理 Azure CLI 的扩展。
运行 az version 以查找安装的版本和依赖库。 若要升级到最新版本,请运行 az upgrade。
示例脚本
如果你还没有针对内容分发网络配置文件的资源组,请使用命令 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