Adding Cloudfare CDN to Azure Storage
Azure Blob storage is a great way to host all the images, videos, documents, and other files required for your website. But you’ll need to use a CDN along with the blob storage. Otherwise you’ll end up making a lot of requests directly to the storage service result in high costs. Azure has a CDN service, but it is a bit pricey. The CDN service by cloudfare is a great alternative.
Assuming you already have a Azure Storage account and a cloudfare account with your websites DNS records, you first need to update your DNS records and add the storage account endpoint. This endpoint can be found in the Azure portal. You can use any custom domain like assets, images or cdn.
You can see in the above picture that the proxy option is turned off. This option is required for the CDN to cache the files. But we have to turn it off for now otherwise it will cause issues with the custom domain verification.
Now we will go to the Azure Portal and open the storage account. Go to the Settings -> Configuration options and turn off the “Secure transfer required” setting. This also causes issues with domain verification.
Now go the Custom domain page in the Networking section. Enter your custom domain for which you added the DNS record and click on save. Note that the DNS record might take some time to be updated.
Once this is done successfully, you can now turn on the proxy service in the Cloudfare for the service to start caching your request to the storage account. Remember to use your custom domain name in your website instead of your storage account endpoint.