Deploy a Static Website to Azure Storage
This tutorial guides you through deploying a static website directly from an Azure Storage account. Static websites can be composed of HTML, CSS, and JavaScript files. By enabling static website hosting, you can serve these files directly from your storage account, providing a cost-effective and scalable solution.
Prerequisites
- An Azure account. If you don't have one, create a free account today.
- A storage account. If you don't have one, you can create a storage account.
- A static website (HTML, CSS, JavaScript) to deploy.
Step 1: Enable Static Website Hosting on Your Storage Account
To enable this feature, navigate to your storage account in the Azure portal. In the left-hand navigation pane, scroll down to the Blob service section and select Static website.
Toggle the status to Enabled. Then, specify your Index document name (typically index.html
) and an optional Error document path (e.g., 404.html
).
After saving, Azure will create a special container named $web
in your storage account. This container will host your website's files.
Note the Primary endpoint URL provided. This is the URL of your static website.
Step 2: Upload Your Website Files
You can upload your website's files to the $web
container using several methods:
- Azure Portal: Navigate to the
$web
container in your storage account and use the "Upload" button. - Azure Storage Explorer: A free, cross-platform tool that provides a graphical interface for managing your Azure Storage resources.
- Azure CLI: Use the command-line interface for automated deployments.
az storage blob upload-batch \ --account-name
(Replace\ --destination-path '$web' \ --source . <your-storage-account-name>
with your actual storage account name. Ensure you are in the root directory of your website files when running this command.)
Make sure your index.html
file (or whatever you specified as the index document) is at the root of the $web
container.
Step 3: Access Your Static Website
Once your files are uploaded, your static website will be accessible via the primary endpoint URL you noted in Step 1. Simply open this URL in your web browser.
For example, if your primary endpoint is https://mystorageaccount.z13.web.core.windows.net
, your website will be available at that address.
Advanced Configurations
Azure Storage static website hosting supports features like:
- Custom Domains: Map your own domain name to your static website.
- CDN Integration: Use Azure CDN to cache your content globally for faster delivery.
- HTTPS: Access your website securely over HTTPS.
For more advanced configurations and best practices, refer to the Azure Storage Static Website Configuration Reference.