alistairphillips.com

I’m : a web and mobile developer based in the Australia.


Caddy Web Server

Importing Configuration Files

The import directive can be used to include additional configuration files. See https://caddyserver.com/docs/caddyfile/directives/import for an example.

import sites-enabled/*

Proxying

To send all request for a domain over to port 8080 on the localhost use the following.

:80 {
    reverse_proxy * localhost:8080
}

Handling errors

Inside your site config add a handle_errors entry like that below. This will send any errors, including gateway unreachable for proxying, to a maintenance.html page. You can optionally rewrite errors to for example 503.html

handle_errors {
                #respond "{http.error.status_code} {http.error.status_text}"
                                #rewrite * /{http.error.status_code}.html
                rewrite * maintenance.html
                root * /usr/share/caddy
                file_server
        }

Automatic HTTPS

SSL certificates can be automatically generated via HTTP, TLS-ALPN, and DNS challenges. See https://caddyserver.com/docs/automatic-https for more information. The DNS challenge requires a custom build of Caddy.

Package support files for custom builds

Custom build steps are detailed over at https://caddyserver.com/docs/build. There are also details on running custom caddy binaries while keeping support files from the caddy package.

This procedure allows users to take advantage of the default configuration, systemd service files and bash-completion from the official package.