Azure static website hosting with blob storage and CDN

Storage blob:

Naivgate to:

  • resources > new > storage
  • create new resource group “storage”
  • create a name
  • select your region
  • select “Azure Blob Storage” as the primary service, “Other” as the primary workload
  • “Standard Performace” is good
  • LRS for redundancy

in the networking tab:

  • “enable public access from all networks”
  • click “review + create”

once the new storage blob is deployed:

  • Goto the new resource and click on “Capabilities” > “Static website”
  • click the ‘enabled’ toggle
  • Specify a default index page and error page [if you are using statically exported nextjs, then specify index.html and 404.html]
  • Click Save

Uploading content

at this stage, you can upload content manually, or you can run an az cli command to deploy your content:

az storage blob upload-batch -s . -d '$web' --account-name xxxxxx --overwrite

Front Door and CDN profile

From azure home dashboard:

  • click “Add Resourse”
  • Search for “Front Door and CDN Profile”
  • select “Explore Other Offerings”
  • select “Azure CDN Standard from Microsoft (Classic)”
  • click “Continue”

on the next screen:

  • Select your subscription and your resource group
  • Fill in a name for your resource
  • select “Global Region” and “Microsoft CDN (Classic)”
  • select “Add a new CDN Endpoint”
  • give your endpoint a name
  • Origin type = “Storage Static Website”
  • select your hostname
  • and “ignore query string” for caching behaviour
  • click review + create

Endpoint

the last step we have to do  is to create a custom domain for our endpoint

Once the Frontdoor + CDN Profile is deployed,

  • click “Go To Resource”
  • click on the endpoint thts already listed
  • click “+ Custom Domain”
  • enter the name for your custom domain, eg app.mysite.com
  • you should see a message about adding a CNAME to DNS – do that :D
  • you may need to wait a while for the message to clear, but once its accepted – Click “Add”

HTTPS / TLS

Once the screen refreshes, you’ll see that https isn’t enabled;

  • click on the domain name, a new screen appears;
  • enable “Custom Domain HTTPS”
  • select CDN MAnaged
  • select TLS/1.2
  • click save

At this point you are set;
with one caveat – as you upload content, its previous versions are still cached, so you need to purge the caches on the CDN

# replace xxxx with the resource name for your "Front Door and CDN profile" resource
az cdn endpoint purge --resource-group storage --profile-name xxxxx --name xxxxx --content-paths '/*'

Leave a Reply