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
Input configuration file to validate.Can be in any format supported by an adapter.
Name of config adapter to apply.Required if the config is not in JSON format. Common adapters:
caddyfileyaml(if installed)
Environment file(s) to load in KEY=VALUE format.Useful if your config references environment variables.
Examples
Validate a Caddyfile
Validate a JSON config
Validate with explicit adapter
Validate with environment file
{env.VARIABLE}, the environment file will be loaded first.
Validate in CI/CD
Validate before reload
Exit Codes
0- Config is valid1- Config is invalid or error occurred
Error Output
If the config is invalid, you’ll see detailed error messages:Validation Stages
The command validates through these stages:- Load config file from disk
- Adapt to JSON if an adapter is specified
- Unmarshal JSON into Go structures
- Provision all modules (calls
Provision()on each) - 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:Related Commands
caddy adapt- Adapt and optionally validatecaddy reload- Reload config in running instancecaddy run- Start Caddy with config