Caddy: the easy webserver

Updated Jan 8, 2023·Published Nov 20, 2022·3 minutes read

    Contents

  1. Configuration
  2. Automatic HTTPS
  3. HTTP/3
  4. Conclusion

Nginx and Apache are often considered the standard of open-source webservers but are sometimes hard to set up properly. But I recently discovered Caddy, a relatively new webserver that is very easy to setup and has some other exiting features.

Configuration #

Caddy is often configured using just one file, the Caddyfile, which has a syntax that is quite similar to that of Nginx. While putting everything in one file might not follow the Unix philosophy, it is very convenient since you don't have to search or symlink to certain files.

To setup a static site, all you need is a section this:

www.example.com { 
    encode gzip
    root * /var/www
    file_server
}

This will host files from /var/www with gzip compresssion.

Having this site switched to Caddy, I prefer the configuration of Caddy to the that of Nginx since it has a lot of features you would want in 2023, like HTTP/2 enabled by default. Also, the language feels more accessible and the documentation website has clear examples.

Automatic HTTPS #

A TLS certificate to encrypt traffic to your website is absolutely required in 2023 and thanks to efforts form Let's Encrypt and certbot it is easier then ever to get the green lock. Still, you need to think about requesting and renewing certificates as a sysadmin.

My favourite feature and what I think is the biggest selling point of Caddy is the automatic HTTPS. Caddy will request a TLS certificate from a CA like Let's Encrypt if you configure it using a configuration like example above where you enter your domain name. It just works™ and fixes all the problems that come with setting up HTTPS manually.

HTTP/3 #

Caddy is one of the first web servers that has HTTP/3 enabled by default. Now that the specification of HTTP/3 has been finalized and many browsers support it, it's cool to use the new technology to make your website load even a little faster. However, I haven't gotten it to work on this site yet (I haven't changed any settings). Maybe it has to do something with the firewall.

Conclusion #

I moved by website from Nginx to Caddy and I was really impressed with how easy it was. If you are also self-hosting websites I would recommend using Caddy because it makes the setup a lot easier and saves a lot of time when tinkering with TLS certificates.

However, I'm not sure how Caddy compares against features of other webservers. Ultimately you must decide whether Caddy is a good fit for you.

categories:sysadmin