Several official documents have already described clearly about how to build a static website on Azure. By following the step-by-step tutorials, one could successfully create its own website without much to bother with. I have collected the scattered pages together which belong to different components here for better references.
- https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website-how-to (required)
This is the basic tutorial talking about how to create a storage service and enable static websites.
After this step: <storage_account>.<region_code>.web.core.windows.net
(primary endpoint) is created.
- https://docs.microsoft.com/en-us/azure/storage/blobs/storage-custom-domain-name (option I)
This is an easier option for one to enable custom domain by adding a CNAME record in one’s www subdomain to direct traffic to the blob. However, this does NOT allow one to either access the static website via the root domain (without www prefix) or secure the website with HTTPS. Since my goal is to achieve both, an Azure CDN is required.
After this step: CNAME record www.<domain_name>.<domain> -> <storage_account>.<region_code>.web.core.windows.net
(primary endpoint) is created.
https://docs.microsoft.com/en-us/azure/cdn/cdn-storage-custom-domain-https (option II)
The reasons of using Azure CDN are straightforward - support HTTPS and rules engine for redirection. This is the tutorial describing how to access storage blobs using an Azure CDN custom domain over HTTPS, which links to multiple documents below:- https://docs.microsoft.com/en-us/azure/cdn/cdn-create-a-storage-account-with-cdn
This one talks about integrating an Azure storage account with Azure CDN.
After this step:
<endpoint_name>.azureedge.net
is created.- https://docs.microsoft.com/en-us/azure/dns/dns-delegate-domain-azure-dns
This one talks about adding a CNAME record mapping to the destination CDN endpoint and associate the domain with the CDN endpoint. However, what is missing here is how to map the root domain to the endpoint. While a CNAME record cannot be placed on a root domain, an A record could. One piece of information sit elsewhere illustrates how to point zone apex to Azure CDN endpoints. With the help of the A record, one can access the site using domain without www prefix.
After this step: A record
www.<domain_name>.<domain> -> <endpoint_name>.azureedge.net
is created; A record<domain_name>.<domain> -> <endpoint_name>.azureedge.net
is also created;- https://docs.microsoft.com/en-us/azure/cdn/cdn-custom-ssl
This is a simple manual of configuring HTTPS. The note left here is that CDN-managed certificates are not available for root domains. Since HTTPS is already available for www subdomain, redirection with the rules engine could be an easy choice.
After this step: HTTPS on
www.<domain_name>.<domain>
is enabled; HTTP 301HTTP -> HTTPS
is enabled.- https://docs.microsoft.com/en-us/azure/cdn/cdn-standard-rules-engine
It provides the solution of enforcing HTTPS via automatic redirection, which serves as a perfect sample for redirecting traffic sent from root domain to the subdomain. A separate rule lies as “if request URL begins with https://domain (to lowercase), then URL redirect moved (with match-request protocol) to hostname www.domain".
After this step: HTTP 301
<domain_name>.<domain> -> www.<domain_name>.<domain>
is enabled.- https://docs.microsoft.com/en-us/azure/cdn/cdn-create-a-storage-account-with-cdn
After setting everything up, the redirection chain is ready.
1 | >>> http://cheng.st |