After switching from NGINX to Caddy on all of my websites, I have come to the conclusion that Caddy is the best webserver in existence. With automatic HTTPS, a simple configuration file, and more, Caddy is just the best webserver overall for general use.
Built-in automatic HTTPS
Caddy can fetch certificates from Let’s Encrypt and ZeroSSL out of the box. HTTPS is enabled by default for eligible domains1, unless you explicitly tell it not to.
Incredible cipher security
Caddy has incredible defaults for TLS/SSL ciphers. Any site you host on Caddy gets a perfect score from Qualys SSL Labs out of the box.2
Dead simple configuration files: Caddy vs NGINX
Caddy’s configuration file format is the easiest out of all the main webserver. The best way for me to demonstrate this simplicity is to compare it to one of the most popular webservers: NGINX.
Serving some static files
The most essential feature you can use a webserver for.
Caddy
caddyfileCopy
|
|
NGINX
nginxCopy
|
|
As you can see, the Caddy config is a lot simpler than the NGINX one. But wait, there’s more! This NGINX config is unencrypted HTTP only, but the Caddy one will automatically request a certificate from Let’s Encrypt, enable HTTPS, and even redirect unencrypted HTTP to HTTPS.
From now on, for the sake of simplicity, I’ll be ignoring HTTPS for the NGINX configs.
PHP (PrivateBin)
The Caddy config for this example is the same as the one used for bin.boba.best. I’ve stripped it down a bit by removing the custom error pages, HSTS, zstd compression, and logging.
Caddy
caddyfileCopy
|
|
NGINX
nginxCopy
|
|
Reverse proxy + static files (Gitea)
This last example is based on git.bbaovanc.com. Just like the last example, I’ve stripped off the custom error pages, HSTS, zstd compression, and logging.
Caddy
caddyfileCopy
|
|
NGINX
nginxCopy
|
|
Although in this case the NGINX config was slightly shorter, I find the Caddy
one a lot more clear and easy to understand. With NGINX, I find it weird how
adding a trailing slash or not defines whether the prefix (/_/static/assets
in
this case) is stripped before searching the filesystem. In Caddy, you can use
the handle_path
directive, instead of just a regular handle
directive.
You can read more about how handle
and handle_path
work in Caddy on the
Caddy docs.
The smaller details
These features might not matter to you, but this is my blog, and I care about them, so I’ll be including them.
Go templates
Caddy is written in Go and supports Go templates. This means you can make simple dynamic content while only using Caddy!
In fact, the official Caddy website is generated entirely using Caddy’s and Go templates!3
Error pages using HTTP Cats
I use this snippet on both bbaovanc.com and boba.best to make custom error pages using images from HTTP Cats. It uses Caddy’s template support to generate some simple HTML to show the error code, name, and cat image.
Beautiful autoindex file browser
Apache and NGINX both have an optional “autoindex” feature which generates a list of files in a directory when there’s no page there. However, it looks very ugly. Caddy, on the other hand, still has a simple index page, but looks a thousand times better.
Coincidentally, it matches the theme of my website very well, so I have to put a border around the image.
-
For the rules on what domains have automatic HTTPS by default, see “Hostname requirements” on the Caddy documentation. ↩︎
-
SSL Labs caps the score to an A if HSTS isn’t enabled. After enabling it, then you get a perfect A+ score. See my website’s score (archived) for an example (bbaovanc.com). ↩︎
-
See more info about templating on the Caddy docs ↩︎
Comments
If you provide an email address, you can enable notifications for replies to your comment. It will not be shown publicly.