Exercise - Deploy a static website to blob storage
Before we explore Content Delivery Networks, let's deploy a static website in Azure Storage to use throughout the module.
Create a Storage Account in Azure Cloud Shell
Start by creating a new storage account to host a static site. When we're finished, you can access this site through the content delivery network.
The free sandbox allows you to create resources in a subset of the Azure global regions. Select a region from this list when you create resources:
- westus2
- southcentralus
- centralus
- eastus
- westeurope
- southeastasia
- japaneast
- brazilsouth
- australiasoutheast
- centralindia
Install the
storage-preview
extension by executing the following command in Azure Cloud Shell. This Azure CLI extension is needed to manage static websites from the CLI. Run the following command in the Cloud Shell terminal window on the right:az extension add --name storage-preview
Run these commands in the Cloud Shell to set up a few shell variables. Use these variables throughout this module to create items such as a storage account name. Replace
<location>
with one of the locations in the region list.STORAGE_ACCOUNT_NAME="cdnsitestorage$RANDOM" \ RESOURCE_GROUP=<rgn>[sandbox resource group name]</rgn> \ LOCATION=<location>
Run this command in the Cloud Shell to create the storage account.
az storage account create \ --name $STORAGE_ACCOUNT_NAME \ --resource-group $RESOURCE_GROUP \ --location $LOCATION \ --sku Standard_LRS \ --kind StorageV2
In the output, find the
"primaryEndpoints"
web url, copy it, and open the link in a web browser. The page that opens indicates that "The requested content doesn't exist". Keep this tab open; we're going to deploy our static content and then refresh the page.
Enable static website hosting on the storage account
In the Cloud Shell, run the following command to enable static website hosting on the storage account.
az storage blob service-properties update \ --account-name $STORAGE_ACCOUNT_NAME \ --static-website \ --404-document 404.html \ --index-document index.html
At the end of the output, you should see the entry:
"staticWebsite": { "enabled": true, "errorDocument_404Path": "404.html", "indexDocument": "index.html" }
Switch to the browser tab displaying the static website and refresh it. You see a message that the requested content doesn't exist.
Upload Files to the Static Website
To upload the website files, execute the following commands:
git clone https://github.com/MicrosoftDocs/mslearn-create-cdn-static-resources-blob-storage source
Navigate to the
source/website-files
foldercd source/website-files
Then upload those files to the $web blob storage container.
az storage blob upload-batch -s . -d \$web --account-name $STORAGE_ACCOUNT_NAME
Check for Website Publication
Switch to the website you opened earlier and refresh the page (press F5). You see the landing page and an image.
Need help? See our troubleshooting guide or provide specific feedback by reporting an issue.