Hugo, Caddy, SSL and Awesome

Fri, Jul 29, 2016

This blog is created with the awesomeness that is Hugo and Caddy Server. Hugo is a static site generator and Caddy Server is a web server that has really cool features like automatic ssl and auto building.

This blog is created with the awesomeness that is Hugo and Caddy Server. Hugo is a static site generator and Caddy Server is a web server that has really cool features like automatic ssl and auto building the site when I push my site to github. Both are written in Go. This is a quick blog post on how its setup.

Hugo

Make sure you install hugo first

Create a new Hugo site.

hugo new site {site}

Go into the site and you will see a folder structure that quite simple to understand. The hugo specific things are the content folder, the archetypes folder and the config.toml file.

Content is generated as sections and pages. you can get a better understanding of this by reading the hugo documentation but simply contect is logically grouped in its containing folder eg content/posts/my-first-post.md would create a post called My First Post and it would generate that when you build the site.

The archetypes are logical groupings of front matter (like any other static site, the settings at the top of a post that give options to the generator such as the title and date of the post). By creating an archetype for a section (remember from above it is the logical grouping of content) you can manually specify default front matter for that section.

Finally the config.toml file contains site wide configuration that you can use to modify the site to make it yours.

Configuration

The next step is to add a theme. They can be found on the Hugo website and you simply put one into the themes folder. Once you have a theme you need to add the following to your config.toml file

theme = "{theme_name}"

While your in the config.toml file, make sure that the

  • base_url is set to the hostname you plan to use for your blog.
  • add both Disqus shortname and Google analytics code for each if you want to include them on your site.

Now we are ready to add some content.

Content

You can create a new post by using the hugo command.

hugo new posts/my-first-post.md

Then edit your file in the content/posts folder.

Build

To build your site run the following command

hugo

Simple! Just that one command and your site has been built into the public directory. Of course you can also your hugo serve to edit a see a live version of your site at localhost:1313 and you can see it in all its glory.

Now all that needs to happen is too happen as initialise a git repository, add all the files (probably can skip the public folder by adding it to a .gitignore file first) and pushing to github (or your preferred git hosting provider). And thats it. A Hugo blog setup and ready to go, there is now no excuse for creating a blog or site.

Caddy

Caddy is really awesome. Written in Go by a group of young, clever programmers, its a web server that unintentionally become a performant, high quality web server that meets nearly everyone’s needs (except perhaps some massive providers). Using a really simple, file based configuration system you can setup a server in a matter of minutes.

I won’t go into the specific details here of how to actually build the server, instead I will just mentioned my setup and maybe later go into the specifics of the setup.

This blog is running on a $5 (USD) a month Digital Ocean Ubuntu 16.04 server. It is using the Caddy Systemd setup to ensure that as long as the computer is on the server is running. My caddy file looks something like

https://samjohnduke.com {
	tls {email address}
	root /var/www/samjohnduke.com/public
	git github.com/samjohnduke/home /opt/git-repo {
		path  git-repo
		then  hugo --destination=/var/www/samjohnduke.com/public
		hook /webhook {webhook secret key}
	}

	log stdout
	gzip
	errors {
		log stderr
		404 404.html
	}
	ext .html
}

With this caddyfile and with caddy running, I have automatic ssl, git deploy and hugo auto build all running on a $5 a month server. (Actually I have about 10 sites running but it works great all the same)

Conclusion

I really like this setup. Its just so simple that nearly anyone could learn to do it in just a few hours. You would need to make sure that you secure the server and keep it updated, but other than that it just works. I can’t stress that enough, there is very little that needs to be configured beyond the basics.

I would definitely recommend that you give this a setup ago if your looking to do something similar.

comments powered by Disqus