Configuring Azure CDN

A Content Delivery Network (CDN) can improve the performance of your websites running in the Azure environment. By replicating the contents of your Blob storage across multiple data centers around the world, Azure CDN can speed up delivery of static content, such as images or stylesheets, as well as streaming media. See Getting started with Azure CDN for details.

You can utilize an Azure CDN service for Kentico projects configured to use Azure storage and for Kentico Azure projects running in Cloud Services.

To start using a CDN for your project, you need to:

  1. Create a CDN service profile on the Azure Management Portal.
  2. Add CDN endpoints to the created profile.
  3. Enable the CDN in Kentico.

Creating a new Azure CDN profile

  1. Open the Azure Management Portal.
  2. Click Create a resource -> Web + Mobile -> CDN -> Quick create.
  3. Fill in the CDN Profile
    1. Enter a name.
    2. Select a Subscription.
    3. Select a Resource Group or create a new one.
    4. Select a pricing tier.
  4. Click Create.

Adding CDN endpoints to the Azure CDN profile

  1. Open the created Azure CDN profile.
  2. On the Overview tab, click the Endpoint button. The Add an endpoint dialog window opens.
    1. Enter a name.
    2. Set the Origin type of the endpoint to Storage.
    3. Select the service from the Origin hostname drop-down list.
    4. (Optional) Set a custom path to the content you want distributed over the CDN.
    5. (Optional) Set a custom host header.
    6. Specify the protocol and port your service runs on (by default, all Azure services use the default HTTP and HTTPS ports)
  3. Click Add.

Note that it may take up to 90 minutes for the new endpoint to propagate through the CDN network. You may receive error code 400 (Bad Request) errors during this time.

Configuring Kentico to use a CDN

After you create a CDN using the management portal, you need to register the CDN in your Kentico project to start using this service.

  1. Open the web.config file of your local project.

  2. Add the CMSAzurePublicContainer and CMSAzureCDNEndpoint keys into the web.config file:

    
    
    
     <appSettings>
         <add key="CMSAzurePublicContainer" value="true" />
         <add key="CMSAzureCDNEndpoint" value="EndpointURL" />
     </appSettings>
    
    
     
  3. Replace EndpointURL with the name of your created CDN endpoint – in the Azure Management Portal, open your Azure CDN profile and locate the hostname of the endpoint associated with your application.

    If your site runs under HTTPS, we recommend you always specify the EndpointURL using the HTTPS protocol as well.

    For example: https://endpoint1.azureedge.net

    Not doing so may result in Mixed Content warnings being logged in your web browser’s console when retrieving files from the CDN.

  4. If your application is running in Azure, redeploy all changes made to the project.

Your project is now ready to use the created Azure CDN service.

Azure CDN content caching

The expiration interval for Azure CDN cache can be defined by the following values:

  1. By the CMSAzureCDNCacheMinutes web.config key. 

  2. By the Cache files (minutes) setting in Settings -> System -> Performance

  3. By the default value defined by Azure. 

This list is ordered by priority, which means that the default Azure value can be overwritten by configuring the Cache files (minutes) key. And this setting can be overwritten by the CMSAzureCDNCacheMinutes web.config key.

If you set the setting and the web.config key to 0 or an invalid value, the default Azure CDN value will be used.