Why?

I’ve been using Apache as my web server ever since I had my first blog. It’s powerful and it’s more than enough for me. So why bother to change? Because Caddy looks so cool:

  • Configuration is simple. Install and setup Apache is not that complicate but Caddy is just way too simple.
  • Automatic HTTPS. Caddy automatically obtains and renews SSL/TLS certs using Let’s Encrypt vs. Apache you have to set it up.
  • Other features that not a big of deal for my personal website: built-in HTTP/2, automatic gzip compression and etc.

Migration

First, install Caddy on my Ubuntu server

1
2
3
4
5
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl 
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg 
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list 
sudo apt update 
sudo apt install caddy

Then config Caddyfile /etc/caddy/Caddyfile for my website

example.com {
	# dir as root of the website
	root * /var/www/example.com
	# enable serving static files from root dir
	file_server
	# enable automatic gzip compression
	enable gzip
	log {
		output file /var/log/caddy/example.com.log {
			# rotate log at specified size
			roll_size 100MB
			# keep at most 5 rotated logs
			roll_keep 5
		}
	}
}

Validate Caddyfile before start Caddy service

1
caddy validate --config /etc/caddy/Caddyfile

Now it’s time to stop Apache web server

1
2
sudo systemctl stop apache2
sudo systemctl disable apache2

And start Caddy

1
2
sudo systemctl start caddy
sudo systemctl enable caddy

That’s it.