Setting up a blog using Hugo and S3

Overview

This post describes how to set up a blog, using the tools I did for this blog. Many of the tools and services I used could be replaced with others; For example, you can replace Hugo with any static website generator, or use Amazon Route53 instead of Cloudfare, or any other domain registrar instead of Gahndi.

Get Domain from Gandi

Create an account at Gandi and buy the domain you want.

Create Blog using Hugo

Hugo is a static site generator written in Go. Since our blog will just be static files, it will be incredibly fast. Follow the instructions at the Hugo Quickstart Guide to create a site using Hugo - I can’t explain better than they already did.

Store Content on S3

Once you have created a site with Hugo, we need to make it available online. To do this, we use S3 for hosting the static pages created by Hugo.

Create a Amazon EC2 account, and create a S3 bucket for your web site. The bucket name should match your site name (for example, www.nathanflath.com). Under the ‘Static Website Hosting’ option, set ‘Enable website hosting’ and set the ‘Index Document’ to index.html.

There will be a ‘Endpoint’ mentioned in this section: Mine is http://www.nathanflath.com.s3-website-us-east-1.amazonaws.com/. Make a note of this address; we’ll use it when setting up DNS.

To push your Hugo blog to S3, I use s3cmd. To push my blog to S3, I first create the files to push with:

hugo -b "http://www.nathanflath.com" --theme=hyde

and push with:

s3cmd put -P --recursive ~/Dropbox/blog/public/ s3://www.nathanflath.com

You may want to put these in a shell script and use cron to push your changes automatically.

Here, ~/Dropbox/blog/public is the path to the ‘public’ directory of my blog, and www.nathanflath.com is my bucket name. -P means to make everything public.

DNS using Cloudfare

You can now view your site using the S3 endpoint - but you want to be able to use the domain name you have. I used Cloudfare to set up the DNS settings - another option is Amazon’s Route53.

Sign up for Cloudfare and add your website. Go to the DNS settings, and add CNAME records for ‘www’ and ‘@’ (which will cause both nathanflath.com and www.nathanflath.com to work). Alias these to your S3 endpoint.

Cloudfare will also give you two nameservers to use; log into Gandi and set your site to use these.

Once DNS settings are refreshed(could be up to a few hours), your site will be up and working.

References

<http://gohugo.io/overview/quickstart>
2. <http://www.danesparza.net/2013/11/cheaper-hosting-on-s3/>
3. <http://s3tools.org/s3cmd>
4. <https://support.cloudflare.com/hc/en-us/articles/200171626-How-do-I-change-my-nameservers-at-Gandi->