Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can serve static content (HTML, CSS, JavaScript, and image files) directly from a container in a general-purpose V2 or BlockBlobStorage account. To learn more, see Static website hosting in Azure Storage.
This article shows you how to enable static website hosting by using the Azure portal, the Azure CLI, or PowerShell.
Static website hosting is a feature that you have to enable on the storage account.
You can enable static website hosting by using the Azure PowerShell module.
Open a Windows PowerShell command window.
Verify that you have Azure PowerShell module Az version 0.7 or later.
Get-InstalledModule -Name Az -AllVersions | select Name,Version
If you need to install or upgrade, see Install Azure PowerShell module.
Sign in to your Azure subscription with the
Connect-AzAccount
command and follow the on-screen directions.Connect-AzAccount -Environment AzureChinaCloud
If your identity is associated with more than one subscription, then set your active subscription to subscription of the storage account that will host your static website.
$context = Get-AzSubscription -SubscriptionId <subscription-id> Set-AzContext $context
Replace the
<subscription-id>
placeholder value with the ID of your subscription.Get the storage account context that defines the storage account you want to use.
$storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>" $ctx = $storageAccount.Context
Replace the
<resource-group-name>
placeholder value with the name of your resource group.Replace the
<storage-account-name>
placeholder value with the name of your storage account.
Enable static website hosting.
Enable-AzStorageStaticWebsite -Context $ctx -IndexDocument <index-document-name> -ErrorDocument404Path <error-document-name>
Replace the
<error-document-name>
placeholder with the name of the error document that will appear to users when a browser requests a page on your site that does not exist.Replace the
<index-document-name>
placeholder with the name of the index document. This document is commonly "index.html".
Upload objects to the $web container from a source directory.
# upload a file
set-AzStorageblobcontent -File "<path-to-file>" `
-Container `$web `
-Blob "<blob-name>" `
-Context $ctx
Note
If the browser prompts users users to download the file instead of rendering the contents, you can append -Properties @{ ContentType = "text/html; charset=utf-8";}
to the command.
Replace the
<path-to-file>
placeholder value with the fully qualified path to the file that you want to upload (For example:C:\temp\index.html
).Replace the
<blob-name>
placeholder value with the name that you want to give the resulting blob (For example:index.html
).
You can view the pages of your site from a browser by using the public URL of the website.
Find the public URL of your static website by using by using the following command:
$storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -Name "<storage-account-name>"
Write-Output $storageAccount.PrimaryEndpoints.Web
Replace the
<resource-group-name>
placeholder value with the name of your resource group.Replace the
<storage-account-name>
placeholder value with the name of your storage account.
Once you've enabled metrics, traffic statistics on files in the $web container are reported in the metrics dashboard.
Click Metrics under the Monitoring section of the storage account menu.
Note
Metrics data are generated by hooking into different metrics APIs. The portal only displays API members used within a given time frame in order to only focus on members that return data. In order to ensure you're able to select the necessary API member, the first step is to expand the time frame.
Click on the time frame button, choose a time frame, and then click Apply.
Select Blob from the Namespace drop down.
Then select the Egress metric.
Select Sum from the Aggregation selector.
Click the Add filter button and choose API name from the Property selector.
Check the box next to GetWebContent in the Values selector to populate the metrics report.
Note
The GetWebContent checkbox appears only if that API member was used within a given time frame. The portal only displays API members used within a given time frame in order to only focus on members that return data. If you can't find a specific API member in this list, expand the time frame.
- Learn how to configure a custom domain with your static website. See Map a custom domain to an Azure Blob Storage endpoint.