created 2024/06/09 category info, internet views 40
caddy is a web server that is extremely powerful yet simple to configure
by default, for every domain block in the configuration file, caddy automatically acquires a let's encrypt certificate for them!! but does not provide a regular http endpoint. if you want regular http (port 80) too you will have to manually specify that
example.com, http://example.com { file_server { root /var/www/ hide .* browse /etc/caddy/browse.tmpl } handle_errors { @404 expression {err.status_code} == 404 rewrite @404 /404.html } }
when a user vists example.com, on either https or http: we serve static files from `/var/www`, using the template `/etc/caddy/browse.tmpl` for directories without an index.html file, but not showing hidden files; we also redirect to a `/404.html` file on a 404 error
AND we don't have to get our hands dirty setting up certificates by hand or with acme.sh or anything to have it encrypted
yes, that's really the whole configuration file for that‼️
using the `reverse_proxy` directive, you can add tls/ssl to any regular service that doesn't support https://, or even just have it automatically be set up for ones that do! i also use this to expose services hosted on other machines that are forwarded to my server with frp
git.zvava.org { reverse_proxy localhost:8080 }
to use a snippet use the `import` directive, eg. `import respond_file ...`
respond to a request with a specific file (second argument) from a specific directory (first argument):
(respond_file) { root * {args[0]} try_files {args[1:]} file_server }