This article applies to both Debian 10 Buster and Ubuntu 20.04 Focal.
What is Caddy?
Caddy is an open source web server that is simple in design, easy to use and has many powerful features. It can handle TLS (SSL) automatically and can use middleware extensions.
Caddy uses a simple configuration syntax to easily configure routing, reverse proxies, redirects, caching and other features. It also supports HTTP/2, QUIC (HTTP/3) and WebSockets protocols to provide fast web performance.
Why try Caddy?
The simple reason for me was that the nginx-quic project was never released and I wanted a simple web server software that supported HTTP/3 and Caddy was the right choice for me at the moment.
Caddy also supports automated certificates, which is especially good for lazy people.
Installing Caddy
We follow the official installation method and first, install some necessary packages.
Then add Caddy’s GPG public key and apt source.
|
|
You can then update your system and install Caddy.
Configuring Caddy
The default Caddyfile
file is located at /etc/caddy/Caddyfile
, the official tutorial is available here, if you are used to Nginx and Apache configuration then you should be very uncomfortable at this point, so let’s take the simplest example.
- we need to bind the domain name
example.com
. - the file for this domain is located at
/var/www/example.com
and the default home page file name isindex.html
. - we need to turn on SSL and automatically redirect http to https.
- we need to set up TLS 1.2 and TLS 1.3 to be enabled, and HSTS Preload to be enabled.
First, set http://example.com/
to redirect to https://example.com/
.
We then write Caddyfile
in accordance with Mozilla’s recommended configuration.
|
|
Of course you can also set www.example.com
to redirect to example.com
.
Then combine all the above into a Caddyfile
file. Put it in /etc/caddy/Caddyfile
and check the Caddy configuration.
|
|
The following output indicates correct configuration.
|
|
For the OCD, you can also spruce up your Caddyfile.
|
|
Finally, restart Caddy.
|
|
After waiting patiently for the SSL certificate to be issued automatically, we can then open our browser console and look at https://example.com/
to see that the SSL certificate has been deployed automatically and that HTTP/3 is on.