How I made my blog cheap to host, customizable, and lightning-fast. — Part 4: Hosting on the Cheap
Part 1: Setting up — Azure DevOps and Our Headless CMS
Part 2: Building out our Angular Site
Part 3: Meet Scully, our Static Site Generator
Part 4: Hosting on the Cheap — you are here
Part 5: Build and Deploy with Azure DevOps
There are lots of places you could host a static site. I have lots of things in Azure already and had heard that you could serve a static site out of blob storage and I wanted to give it a shot. It’s cheap and low on complexity.
When I say cheap, it’s almost free. I used the pricing calculator, and set it up to have the following options:
- 10,000 write operations
- 10,000 list and create container operations
- 10,000,000 read operations
The monthly price was $4.14. If you drop it down to 1 million reads, the price plummets to $0.54. We’re also going to be putting all the reads onto our CDN, so we’re likely to pay pennies for the storage account.
Here’s how to set it up:
Create an Account/ Login to Azure
Create a Storage account
- Click “Create a Resource”
- Search for “Storage Accounts”
- Click “Create”
- Ensure “Account Kind” is set to “StorageV2” and set other options as you’d like
- Click “Review and Create”
- Wait for it, it might take a minute or two to complete
Set up the Static Website
- Open the Storage Account you created
- Find the “Static website” blade
- Set the toggle for “Static website” to “Enabled”
- Click “Save”
Set up a CDN
I’m going to assume you want an Https domain as that is pretty standard now. If you only want Http, it’s easier and the steps are here.
For Https we need to first set up a Content Delivery Network(CDN). A CDN puts your content on different servers all over the world and delivers the one closest to your user when they request it from your URL. It’s something you can do when your site is all just static filed. It’s amazing because it is going to make our site even faster for the end-user, the cost is that our updates are not instantaneous. We have to wait for them to propagate through the CDN. We can, and will, request a purge of the CDN when we update but it takes a few minutes.
The cost of the CDN varies based on how much content you’re serving and what region it’s being served from. Pricing (as of 3/26/2021) ranges from $0.08-$0.23/GB for the first 10TB. If you have a personal blog without a ton of traffic, the cost should be nominal.
Here’s how to set it up:
- Open your Storage Account
- Under “Blob Service” select “Azure CDN”
- Select your options
- make sure that the “origin hostname” field is set to your blobs endpoint (e.g. mystorageaccount.z5.web.core.windows.net)
- Click “Create”
Once the creation completes you should have a new resource called an “endpoint.”
Set up your Custom Domain
- Open the endpoint created above.
- Note the “Endpoint hostname” value
- Go to your DNS provider and create a CNAME record that points to the hostname. You can set the “name” value of the record to “cdnverify” so long as you change the “data” value to “cdnverify.yourendpoint.azureedge.net”. This will allow you to verify the name without interrupting your website’s current DNS.
- Wait for the DNS change to propagate
- Go back to your endpoint in Azure
- Click the “Custom Domains” blade.
- In the top left select the “+ Custom Domain” to add a custom domain.
- Add your domain
- Toggle Https to “On”
- Set “Certificate management type” to “CDN Managed” **
* if you want to use your root domain instead of www.mydomain.com, azure doesn’t support that with their free certificate. There are two paths I know to get around this.
Path 1: Go to your Domain provider and forward the root to www. Here are instructions for Google Domains (yours may vary). This is what I did. Mine looks like this:
If you have any content in your $web blob, you should now be able to browse it on your domain. If you don’t have anything in there, but want to try it, just use Azure Storage Explorer to drop a simple index.html file in there.
We’re live now! The last thing for us to do is create our build and release pipelines. Let’s go.