Setup of a Caddy HTTP Server on Fedora 37

This tutorial installs a Caddy HTTP server with TLS/HTTPS.

Caddy does all what we expect from a modern website automatically. No extra configuration is necessary to serve HTTPS. Certificates are obtained and renewed for all domain names. Also it redirects from the HTTP port by default.

Prerequisites

  • Being firm in using the command line.

  • A domain name, called foo.net in this tutorial.

  • A Fedora server, set up as depicted in Setup of a Server with Fedora 37.

Install

Caddy

# Install
sudo dnf install caddy

# Start the server on each boot
sudo systemctl enable caddy.service

# Start the server now
sudo systemctl start caddy.service

Firewall

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
sudo ufw status

Configure

Create log directory:

sudo mkdir /var/log/caddy
sudo chown caddy /var/log/caddy
sudo chgrp caddy /var/log/caddy

Create source directory:

sudo mkdir /var/www/foo

sudo nvim /etc/caddy/Caddyfile.d/foo.net.caddyfile:

foo.net {
    root * /var/www/foo
    file_server
    log {
        output file /var/log/caddy/foo.net-access.log
    }
}
sudo systemctl restart caddy

That's really all it needs to obtaine certificates for all domain names, serve a static website over HTTPS, and also to redirect from HTTP. See https://caddyserver.com/docs/caddyfile/patterns or https://caddyserver.com/docs/automatic-https for more information.

Copy project to server

rsync -avz --delete -e ssh build/html/ root@h1:/var/www/foo