0
0
Azurecloud~5 mins

CDN with custom domains in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
A CDN helps deliver your website content faster by storing copies closer to users. Using a custom domain with your CDN makes your website address look professional and easy to remember.
When you want your website to load faster for visitors around the world.
When you want to use your own website name instead of a default CDN address.
When you want to secure your website with HTTPS using your custom domain.
When you want to improve your website's reliability by using CDN caching.
When you want to reduce the load on your main web server by serving static files from the CDN.
Config File - azure-cdn-custom-domain.json
azure-cdn-custom-domain.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Cdn/profiles",
      "apiVersion": "2023-05-01",
      "name": "myCdnProfile",
      "location": "global",
      "sku": {
        "name": "Standard_Microsoft"
      },
      "properties": {}
    },
    {
      "type": "Microsoft.Cdn/profiles/endpoints",
      "apiVersion": "2023-05-01",
      "name": "myCdnProfile/myEndpoint",
      "dependsOn": [
        "Microsoft.Cdn/profiles/myCdnProfile"
      ],
      "properties": {
        "originHostHeader": "myorigin.azurewebsites.net",
        "origins": [
          {
            "name": "myOrigin",
            "properties": {
              "hostName": "myorigin.azurewebsites.net"
            }
          }
        ],
        "isHttpAllowed": true,
        "isHttpsAllowed": true
      }
    },
    {
      "type": "Microsoft.Cdn/profiles/endpoints/customDomains",
      "apiVersion": "2023-05-01",
      "name": "myCdnProfile/myEndpoint/myCustomDomain",
      "dependsOn": [
        "Microsoft.Cdn/profiles/endpoints/myCdnProfile/myEndpoint"
      ],
      "properties": {
        "hostName": "www.example.com"
      }
    }
  ]
}

This template creates a CDN profile and endpoint in Azure.

The profile is the container for your CDN settings.

The endpoint points to your original website (origin).

The custom domain links your own website name to the CDN endpoint.

Commands
This command deploys the CDN profile, endpoint, and custom domain to your Azure resource group.
Terminal
az deployment group create --resource-group example-rg --template-file azure-cdn-custom-domain.json
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded" } }
--resource-group - Specifies the Azure resource group to deploy to
--template-file - Specifies the ARM template file to use for deployment
This command checks the details of the custom domain linked to your CDN endpoint to confirm it was created.
Terminal
az cdn custom-domain show --resource-group example-rg --profile-name myCdnProfile --endpoint-name myEndpoint --name myCustomDomain
Expected OutputExpected
{ "hostName": "www.example.com", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-rg/providers/Microsoft.Cdn/profiles/myCdnProfile/endpoints/myEndpoint/customDomains/myCustomDomain", "name": "myCustomDomain", "resourceState": "Active" }
--resource-group - Specifies the Azure resource group
--profile-name - Specifies the CDN profile name
--endpoint-name - Specifies the CDN endpoint name
--name - Specifies the custom domain name
This command enables HTTPS on your custom domain so visitors get a secure connection.
Terminal
az cdn custom-domain enable-https --resource-group example-rg --profile-name myCdnProfile --endpoint-name myEndpoint --name myCustomDomain
Expected OutputExpected
{ "customHttpsProvisioningState": "Enabling", "customHttpsProvisioningSubstate": "InProgress" }
--resource-group - Specifies the Azure resource group
--profile-name - Specifies the CDN profile name
--endpoint-name - Specifies the CDN endpoint name
--name - Specifies the custom domain name
This command shows the status of the CDN endpoint to verify it is running and serving content.
Terminal
az cdn endpoint show --resource-group example-rg --profile-name myCdnProfile --name myEndpoint
Expected OutputExpected
{ "hostName": "myEndpoint.azureedge.net", "resourceState": "Running", "isHttpAllowed": true, "isHttpsAllowed": true }
--resource-group - Specifies the Azure resource group
--profile-name - Specifies the CDN profile name
--name - Specifies the CDN endpoint name
Key Concept

If you remember nothing else from this pattern, remember: linking your own website name to a CDN endpoint makes your site faster and more professional.

Common Mistakes
Not creating a DNS CNAME record pointing the custom domain to the CDN endpoint hostname.
Without this DNS record, visitors cannot reach your CDN through your custom domain.
Create a CNAME record in your domain registrar that points your custom domain (e.g., www.example.com) to the CDN endpoint hostname (e.g., myEndpoint.azureedge.net).
Trying to enable HTTPS on the custom domain before the DNS CNAME record is active.
HTTPS provisioning requires the domain to be verified via DNS, so it will fail if DNS is not set up.
Wait for DNS propagation after creating the CNAME record before enabling HTTPS.
Using HTTP only on the CDN endpoint and custom domain.
This leaves your website insecure and can cause browsers to warn visitors.
Always enable HTTPS on your CDN custom domain for secure connections.
Summary
Deploy a CDN profile and endpoint with an origin pointing to your website.
Add a custom domain to the CDN endpoint to use your own website name.
Verify the custom domain and enable HTTPS for secure, fast content delivery.