ยง2023-07-01

Caddy User Guide

Caddy is a HTTP/2 capable web server with automatic HTTPS.


$ sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# Source: Caddy
# Site: https://github.com/caddyserver/caddy
# Repository: Caddy / stable
# Description: Fast, multi-platform web server with automatic HTTPS


deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main

deb-src [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main

$ sudo apt update
$ sudo apt install caddy

$ grep caddy /etc/passwd
caddy:x:998:998:Caddy web server:/var/lib/caddy:/usr/sbin/nologin

$ ls /etc/caddy/
Caddyfile  Caddyfile.ori

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

: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

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

For ArchLinux

  1. Install
$ sudo pacman -S caddy
$ caddy version
v2.6.4
  1. config file /etc/caddy/Caddyfile
  2. /usr/share/caddy/index.html default index.html
  3. systemctl start caddy CaddyIndexHtml.png
  4. Directory listing
$ sudo cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.ori
$ diff /etc/caddy/Caddyfile /etc/caddy/Caddyfile.ori 
24,25c24
<       # root * /usr/share/caddy
<       root * /opt/munetakaJupyterHub
---
>       root * /usr/share/caddy
28c27
<       file_server browse
---
>       file_server
  1. markdown support

still fails

$ sudo pacman -S go
$ go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
go: downloading github.com/caddyserver/xcaddy v0.3.4
go: downloading github.com/Masterminds/semver/v3 v3.1.1
go: downloading github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
$ go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
$ cd ~/go/bin
$ ./xcaddy build --with github.com/simPod/caddy-md