Skip to content

Azure Static Website

Tomáš Kapin edited this page Jun 4, 2023 · 12 revisions

This article describes creation of an Azure static website with a custom domain backed up by Azure DNS Zone and Azure CDN provided HTTPS certificates.

Create Azure static website

Azure storage (v2) supports hosing a static website off of a blob storage.

Create new azure storage

  1. The storage name has to be unique across the whole Azure
  2. Create a new resource group for the storage (e.g., "web1-rg")
  3. Set the name of the storage (e.g., "web1tkdev")
  4. Select region (e.g., "Europe (West Europe)")
  5. Keep everything on default, optionally removing Enable soft delete for blobs, containers and file shares
  6. Create the storage

Enable the static website

  1. Navigate to the storage resource
  2. Select "Static website"
  3. Select "Enable"
  4. Specify "Index document name" to "index.html"
  5. Optionally, specify "Error document name" to "error.html"

Upload the content

Content can be uploaded either via the Azure Web UI, or the Azure CLI. To enable uploading content through the Azure CLI, set the access control first.

  1. Navigate to Access Control (IAM)
  2. Select "Role assignments" tab
  3. Click on "Add" and select "Add role assignment" from the dropdown
  4. Select "Storage Blob Data Contributor" from the built-in roles and click "Next"
  5. Click "+ Select Members" and select your identity
  6. Process to "Review + assign"

The static website content is stored in the $web blob. To upload content to this blob from the CLI, run

az storage blob upload-batch --account-name $azStorageName -d '$web' -s $contentPath --pattern '*' --overwrite --validate-content --auth-mode login

Associate custom domain to the website

To host the static website with a custom domain with HTTPS support, the easiest way is to use Azure CDN to manage the SSL certificates.

Create CDN Entry

  1. Navigate to the storage resource
  2. Select "Azure CDN"
  3. Use existing CDN presuming you have one (or create new)
  4. Fill in the "CDN endpoint name" (has to be unique across the .azureedge.net domain
    1. As convention, use your custom domain you want to use, replacing dots with hyphens
  5. [Important] From the "Origin hostname" dropdown, select the "(Static website)" instead of the "(Blob)" option
  6. Create

At this point, the static website will be accessible on the address specified in the "CDN endpoint name" above (ending in .azureedge.net).

Create DNS Record

Presuming you have the Azure DNS Zone with a custom domain supported, you can bind custom domain to your static website.

  1. Navigate to the Azure DNS zone resource you want to use
  2. Select "+ Record set" at the top
  3. Fill in the "Name"
  4. Select "Type" to "CNAME" in the dropdown
  5. Select "Alias record set" to "Yes"
  6. Keep "Alias type" to "Azure resource"
  7. Keep (or select) the Azure subscription
  8. Set the "Azure resource" to the CDN entry created above
  9. Keep the TTL settings
  10. Click "OK"

There will be two CNAME records created. One with the name just created and other one with a cdnverify prefix. At this moment, the DNS record is set and it just needs to be associated with CDN custom domain.

Create the CDN custom domain entry

  1. Navigate to the CDN resource again
  2. Select the endpoint corresponding to your static website
  3. Click on the "+ Custom domain"
  4. Fill in the domain name of the DNS record set above

Provisioning of the SSL certificate will take up to 10 minutes, after which the Azure storage backed-up static website will be available on the custom domain.

Clone this wiki locally