How to Integrate Azure CDN with Web Apps: A Step-by-Step Guide
Boost your Azure Web App’s performance by integrating it with Azure CDN! This guide walks you through setting up a CDN profile, creating an endpoint, configuring custom domains & caching, and optimizing performance & security. Follow these steps to accelerate content delivery and enhance user experience.
1. Prerequisites
- An Azure account with an active subscription.
- A deployed Azure Web App.
- Basic familiarity with Azure Portal.
2. Create an Azure Web App (if not already created)
If you don’t have a Web App yet, follow these steps:
- Go to Azure Portal → App Services → Create.
- Fill in:
- Subscription: Select your subscription.
- Resource Group: Create a new or select an existing one.
- Name: Unique name (e.g.,
mywebapp123.azurewebsites.net
). - Publish: Code or Docker Container.
- Runtime Stack: Choose the appropriate one (e.g., .NET, Java, Node.js).
- Region: Select a region near your audience.
- Click Review + Create → Create.
- Wait for deployment and click Go to resource.
3. Create an Azure CDN Profile
Azure CDN improves the performance and reliability of your web app by caching content in globally distributed locations.
- Go to Azure Portal → Search for CDN Profiles.
- Click Create.
- Fill in:
- Subscription: Select your subscription.
- Resource Group: Choose the same as your Web App.
- CDN Profile Name: Unique name (e.g.,
mycdnprofile
). - Pricing Tier: Choose a provider:
- Microsoft Standard (recommended for general use).
- Akamai Standard/Premium.
- Verizon Standard/Premium.
- Region: Keep it the same as the Web App.
- Click Review + Create → Create.
4. Create an Azure CDN Endpoint
- Open your CDN Profile.
- Click + Endpoint.
- Configure:
- Name: Unique name (e.g.,
mycdnendpoint
). - Origin Type: Choose App Service.
- Origin Hostname: Select your Web App.
- Origin Host Header: Leave as default.
- Name: Unique name (e.g.,
- Click Add.
- Wait for deployment.
5. Configure Custom Domain (Optional)
If you want to use a custom domain (e.g., cdn.mywebsite.com
), follow these steps:
- In your CDN Endpoint, go to Custom Domains.
- Click + Custom domain.
- Enter your custom domain (e.g.,
cdn.mywebsite.com
). - Update your DNS records:
- Add a CNAME record pointing to your CDN Endpoint (
mycdnendpoint.azureedge.net
).
- Add a CNAME record pointing to your CDN Endpoint (
- Click Validate and Save.
6. Enable HTTPS (Optional)
- In your CDN Endpoint, go to Custom Domains.
- Select your domain → Enable HTTPS.
- Choose CDN-Managed or bring your own SSL certificate.
- Click Save.
7. Test and Verify CDN
- Go to your CDN Endpoint URL (e.g.,
https://mycdnendpoint.azureedge.net
). - Check if content loads correctly.
- Use browser developer tools (F12 → Network tab) to verify CDN caching.
- Test performance using Azure CDN verification tool.
8. Configure Caching Rules (Optional)
If you need custom caching policies, go to:
- Azure CDN Profile → Endpoint → Caching Rules.
- Configure:
- Bypass caching for dynamic content.
- Force caching for static assets (CSS, JS, images).
- Expiration policies.
9. Purge CDN Cache (When Needed)
To refresh content, go to:
- Azure CDN Endpoint → Purge → Enter file path or
/*
to clear all.
10. Automate Deployment (CI/CD)
You can use Azure DevOps or GitHub Actions to automate Web App and CDN deployments.