使用 Azure CLI 建立 Azure 內容傳遞網路設定檔和端點

重要

Azure CDN Standard from Microsoft (classic) 將於 2027 年 9 月 30 日淘汰。 為了避免任何服務中斷,請務必在 2027 年 9 月 30 日之前,移轉您的 Azure CDN Standard from Microsoft (classic) 設定檔至 Azure Front Door Standard 或 Premium 層。 如需詳細資訊,請參閱 Azure CDN Standard from Microsoft (classic) 淘汰

除了 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 內容傳遞網路端點相關聯之前,您必須先使用 Azure DNS 或您的 DNS 提供者建立正式名稱 (CNAME) 記錄以指向您的內容傳遞網路端點。 如需詳細資訊,請參閱建立 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 命令