0
0
AzureHow-ToBeginner · 4 min read

How to Use CDN with Azure: Setup and Best Practices

To use Azure CDN, create a CDN profile and endpoint in the Azure portal or via Azure CLI, then link it to your storage or web app. This caches your content globally, speeding up delivery to users.
📐

Syntax

Using Azure CDN involves creating a CDN profile and a CDN endpoint. The profile groups your CDN endpoints, and the endpoint points to your origin (like a storage account or web app).

Key parts:

  • az cdn profile create: Creates a CDN profile.
  • az cdn endpoint create: Creates an endpoint linked to your origin.
  • --origin: The source URL or storage to cache.
  • --resource-group: Your Azure resource group.
bash
az cdn profile create --name <profile-name> --resource-group <resource-group> --location <location> --sku Standard_Microsoft
az cdn endpoint create --name <endpoint-name> --profile-name <profile-name> --resource-group <resource-group> --origin <origin-hostname>
💻

Example

This example creates a CDN profile and endpoint that caches content from an Azure Storage account.

bash
az group create --name MyResourceGroup --location eastus
az storage account create --name mystorageacct123 --resource-group MyResourceGroup --location eastus --sku Standard_LRS
az cdn profile create --name MyCDNProfile --resource-group MyResourceGroup --location eastus --sku Standard_Microsoft
az cdn endpoint create --name MyCDNEndpoint --profile-name MyCDNProfile --resource-group MyResourceGroup --origin mystorageacct123.blob.core.windows.net
Output
ResourceGroup 'MyResourceGroup' created. Storage account 'mystorageacct123' created. CDN profile 'MyCDNProfile' created. CDN endpoint 'MyCDNEndpoint' created and linked to origin 'mystorageacct123.blob.core.windows.net'.
⚠️

Common Pitfalls

  • Not setting the correct origin hostname causes CDN to fail fetching content.
  • Using the wrong SKU (Standard vs Premium) may limit features you need.
  • For storage origins, ensure the container is public or has proper access.
  • For custom domains, you must validate domain ownership before use.
bash
## Wrong origin example (missing .blob.core.windows.net)
az cdn endpoint create --name BadEndpoint --profile-name MyCDNProfile --resource-group MyResourceGroup --origin mystorageacct123

## Correct origin example
az cdn endpoint create --name GoodEndpoint --profile-name MyCDNProfile --resource-group MyResourceGroup --origin mystorageacct123.blob.core.windows.net
📊

Quick Reference

Remember these tips when using Azure CDN:

  • Create a CDN profile before endpoints.
  • Use the correct origin URL format.
  • Choose SKU based on your needs (Standard_Microsoft is common).
  • Make sure your origin content is accessible.
  • Use Azure portal or CLI for easy setup.

Key Takeaways

Create a CDN profile and endpoint to start using Azure CDN.
Link the endpoint to a valid origin like a storage account or web app.
Ensure your origin content is publicly accessible or properly authorized.
Use the correct origin hostname format to avoid errors.
Choose the right SKU for your performance and feature needs.