Static website hosting in Azure Storage

In this article

You can serve static content (HTML, CSS, JavaScript, and image files) directly from a storage container named $web. Hosting your content in Azure Storage enables you to use serverless architectures that include Azure Functions and other Platform as a service (PaaS) services.

Setting up a static website

Static website hosting is a feature that you have to enable on the storage account.

To enable static website hosting, select the name of your default file, and then optionally provide a path to a custom 404 page. If a blob storage container named $web doesn't already exist in the account, one is created for you. Add the files of your site to this container.

The URL of your site contains a regional code. For example the URL https://contosoblobaccount.z22.web.core.windows.net/ contains regional code z22.

While that code must remain the URL, it is only for internal use, and you won't have to use that code in any other way.

The index document that you specify when you enable static website hosting, appears when users open the site and don't specify a specific file (For example: https://contosoblobaccount.z22.web.core.windows.net).

If the server returns a 404 error, and you have not specified an error document when you enabled the website, then a default 404 page is returned to the user.

Impact of the setting the public access level of the web container

You can modify the public access level of the $web container, but this has no impact on the primary static website endpoint because these files are served through anonymous access requests. That means public (read-only) access to all files.

The following screenshot shows the public access level setting in the Azure portal:

While the primary static website endpoint is not affected, a change to the public access level does impact the primary blob service endpoint.

For example, if you change the public access level of the $web container from Private (no anonymous access) to Blob (anonymous read access for blobs only), then the level of public access to the primary static website endpoint https://contosoblobaccount.z22.web.core.windows.net/index.html doesn't change.

However, the public access to the primary blob service endpoint https://contosoblobaccount.blob.core.windows.net/$web/index.html does change from private to public. Now users can open that file by using either of these two endpoints.

Content Delivery Network (CDN) and Secure Socket Layer (SSL) support

To make your static website files available over your custom domain and HTTPS, see Using the Azure CDN to access blobs with custom domains over HTTPS. As a part of this process, you need to point your CDN to the primary static website endpoint as opposed to the primary blob service endpoint. You might need to wait a few minutes before your content is visible as the CDN configuration is not immediately executed.

When you update your static website, be sure to clear cached content on the CDN edge servers by purging the CDN endpoint. For more information, see Purge an Azure CDN endpoint.

Note

HTTPS is supported natively through the account web endpoint, so the web endpoint is accessible via both HTTP and HTTPS. However, if the storage account is configured to require secure transfer over HTTPS, then users must use the HTTPS endpoint. For more information, see Require secure transfer in Azure Storage.

The use of custom domains over HTTPS requires the use of Azure CDN at this time.

Pricing

You can enable static website hosting free of charge. You're billed only for the blob storage that your site utilizes and operations costs. For more details on prices for Azure Blob Storage, check out the Azure Blob Storage Pricing Page.

Metrics

You can enable metrics on static website pages. Once you've enabled metrics, traffic statistics on files in the $web container are reported in the metrics dashboard.