Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Caddy Webserver Cheatsheet

Table of Contents

Validate Caddy Config File

If you have a config file for Caddy, you can validate it like so:

docker run \
  -v $PWD/config.json:/etc/caddy/config.json \
  caddy \
  caddy validate --config /etc/caddy/config.json

I tested this works with both JSON and Caddyfile formats (using the appropriate extensions).

Convert Caddyfile To JSON

The main benefit for me about Caddy is that it can be completely configured through JSON. However, a lot of the documentation examples only show the Caddyfile format. In order to convert a Caddyfile to its full JSON format, one can run:

docker run \
  -v $PWD/Caddyfile:/etc/caddy/Caddyfile \
  caddy \
  caddy adapt --config /etc/caddy/Caddyfile --pretty | cat > output.json

This assumes you have a file at the same level called Caddyfile and will create a corresponding output.json file which you can then use.

Last updated: 13th April 2024
First published: 13th April 2024