Skip to main content
The caddy validate command tests whether a configuration file is valid by loading and provisioning it.

Usage

Description

Loads and provisions the provided config, but does not start running it. This reveals any errors with the configuration through the loading and provisioning stages. This is useful for:
  • Testing configs before deploying
  • CI/CD pipelines to validate PRs
  • Pre-flight checks before reloading
  • Catching errors early without affecting running instances
Validation loads the config and provisions all modules, but some errors may only appear at runtime (e.g., network binding issues).

Flags

string
required
Input configuration file to validate.Can be in any format supported by an adapter.
string
default:""
Name of config adapter to apply.Required if the config is not in JSON format. Common adapters:
  • caddyfile
  • yaml (if installed)
string[]
default:"[]"
Environment file(s) to load in KEY=VALUE format.Useful if your config references environment variables.

Examples

Validate a Caddyfile

If valid, outputs:

Validate a JSON config

Validate with explicit adapter

Validate with environment file

If your config uses {env.VARIABLE}, the environment file will be loaded first.

Validate in CI/CD

Validate before reload

This ensures you only reload if the config is valid.

Exit Codes

  • 0 - Config is valid
  • 1 - Config is invalid or error occurred

Error Output

If the config is invalid, you’ll see detailed error messages:
Or for JSON syntax errors:
Or for validation errors:

Validation Stages

The command validates through these stages:
  1. Load config file from disk
  2. Adapt to JSON if an adapter is specified
  3. Unmarshal JSON into Go structures
  4. Provision all modules (calls Provision() on each)
  5. Validate all modules (calls Validate() on each)
This catches most errors, but some issues (like port conflicts) only appear when the server actually starts.

What Gets Validated

Syntax errors

Unknown directives

Invalid values

Missing required fields

Module dependencies

If a module requires another module to be configured:

What Doesn’t Get Validated

Some things only fail at runtime:
  • Port binding - Can’t check if port is available until binding
  • File permissions - Can’t check file access until opening
  • Network connectivity - Can’t check DNS/network until connecting
  • TLS certificate acquisition - Can’t validate ACME until runtime

Use Cases

1. Pre-deployment validation

2. GitHub Actions CI

3. Pre-commit hook

.git/hooks/pre-commit:

4. Development workflow

Combining with adapt

For Caddyfiles, you might want to see the adapted JSON too:
This does both: adapts to JSON and validates it.