Caddy’s native JSON configuration format with complete control over all features
JSON is Caddy’s native configuration format. While the Caddyfile is more human-friendly, JSON provides complete control over Caddy’s configuration with explicit structure and validation.
Every configuration in Caddy is ultimately JSON. When you use a Caddyfile, it’s converted (adapted) to JSON before being used. The JSON format is expressed natively as a Go struct and can be manipulated through Caddy’s admin API.
Caddy config is expressed natively as a JSON document. If you prefer not to work with JSON directly, there are many config adapters available that can convert various inputs into Caddy JSON.
From caddy.go:46-95, the top-level configuration structure:
type Config struct { Admin *AdminConfig `json:"admin,omitempty"` Logging *Logging `json:"logging,omitempty"` // StorageRaw is a storage module that defines how/where Caddy // stores assets (such as TLS certificates). StorageRaw json.RawMessage `json:"storage,omitempty" caddy:"namespace=caddy.storage inline_key=module"` // AppsRaw are the apps that Caddy will load and run. AppsRaw ModuleMap `json:"apps,omitempty" caddy:"namespace="`}
Configures Caddy’s API endpoint from admin.go:67-125:
type AdminConfig struct { // If true, the admin endpoint will be completely disabled. Disabled bool `json:"disabled,omitempty"` // The address to which the admin endpoint's listener should // bind itself. Default: localhost:2019 Listen string `json:"listen,omitempty"` // If true, CORS headers will be emitted EnforceOrigin bool `json:"enforce_origin,omitempty"` // The list of allowed origins/hosts for API requests Origins []string `json:"origins,omitempty"` // Options pertaining to configuration management Config *ConfigSettings `json:"config,omitempty"` // Identity and remote administration Identity *IdentityConfig `json:"identity,omitempty"` Remote *RemoteAdmin `json:"remote,omitempty"`}
type Logging struct { // Sink is the destination for all unstructured logs emitted // from Go's standard library logger Sink *SinkLog `json:"sink,omitempty"` // Logs are your logs, keyed by an arbitrary name. // The default log can be customized by defining // a log called "default" Logs map[string]*CustomLog `json:"logs,omitempty"`}
The default storage module is file_system with a platform-specific default path. On Linux, this is typically $HOME/.local/share/caddy or /var/lib/caddy.