Aller au contenu

Ubuntu | Caddy

Installer Caddy

Installer la version stable
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
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
sudo apt update
sudo apt install caddy

Paramétrer pour Docker

Modifier le Caddyfile
editor /etc/caddy/Caddyfile

Dans le répertoire /etc/caddy, modifier le fichier Caddyfile.

/etc/caddy/Caddyfile
:80 {
# Set this path to your site's directory.
# root * /usr/share/caddy
# Enable the static file server.
# file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
reverse_proxy :3000
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}
Redémarrer caddy.
systemctl reload caddy

Pour que les modifications soient effectives, il faut redémarrer caddy.

Nom de domaine

Tester le nom de domaine
curl "https://cloudflare-dns.com/dns-query?name=example.com&type=A" \
-H "accept: application/dns-json"
/etc/caddy/Caddyfile
:80 {
https://exemple.fr {
reverse_proxy :3000
}

Caddy prend en charge la navigation https.

Redirection wwww

/etc/caddy/Caddyfile
https://www.example.fr {
redir https://exampe.fr permanent
}
https://exemple.fr {
reverse_proxy :3000
}

Sauvegarder et relancer caddy.

Lighthouse

Pour améliorer les performances de notre site statique, il nous faudra l’encoder. Voici un exemple de configuration avec gzip.

/etc/caddy/Caddyfile
https://www.example.fr {
redir https://exampe.fr permanent
}
https://exemple.fr {
encode gzip
reverse_proxy :3000
}