89.3 Caddy Web Server


Caddy is a fast and simple to configure web server supporting https by default and handling the Let’s Encrypt certificates.

wajig install debian-keyring debian-archive-keyring apt-transport-https
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
wajig update 
wajig install caddy

Now enable Caddy, which also ensures it is started on boot, start it up, and check its status:

sudo systemctl enable caddy
sudo systemctl start caddy
sudo systemctl status caddy

Browse to your server with http and you should now see the default Caddy home page.

You can check the current version of caddy with:

caddy version

The default Caddy configuration file is in /etc/caddy/Caddyfile and only sets up a http based server based on files from /usr/share/caddy.

:80 {
    root * /usr/share/caddy

A more common configuration is to support http with automatic redirect to the secure https using your own domain name, with files served from /var/www/html/. You can replace the default Caddyfile with the following. Be sure to replace example.org with your own domain name.

sudo emacs /etc/caddy/Caddyfile
example.org {
        root * /var/www/html

Create a new web page at /var/www/html/index.html:

sudo mkdir -p /var/www/html
echo "Welcome" | sudo tee /var/www/html/index.html
sudo systemctl reload caddy

Visit your web site again to ensure https://example.org now works.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0