This page is about Caddy 2, which is currently in beta. Click here for the old Caddy 1 site. Thank you for your patience as we transition!
Documentation
Caddy 2 is beta software. It is ready for production, but some things will change between releases; check the release notes before upgrading.

Conventions

The Caddy ecosystem adheres to a few conventions to make things consistent and intuitive across the platform.

Network addresses

When specifying a network address to dial or bind, Caddy accepts a string in the following format:

network/address

The network part is optional, and is anything that Go's net package recognizes. The default network is tcp. If a network is specified, a single forward slash / must separate the network and address portions.

The address part may be any of these forms:

  • host
  • host:port
  • :port
  • /path/to/unix/socket

The host may be any hostname, resolvable domain name, or IP address.

The port may be a single value (:8080) or an inclusive range (:8080-8085). A port range will be multiplied into singular addresses. Not all config fields accept port ranges. The special port :0 means any available port.

A unix socket path is only acceptable when using a unix* network type. The forward slash that separates the network and address is not considered part of the path.

Valid examples:

:8080
127.0.0.1:8080
localhost:8080
localhost:8080-8085
tcp/localhost:8080
tcp/localhost:8080-8085
udp/localhost:9005
unix//path/to/socket

Placeholders

Caddy's configuration supports the use of placeholders (variables). Using placeholders is a simple way to inject dynamic values into a static configuration.

Placeholders are bounded on either side by curly braces { } and contain the variable name inside, for example: {foo.bar}. Variable names are typically namespaced with dots to avoid collisions across modules.

Which placeholders are available depends on the context. Not all placeholders are available in all parts of the config. For example, the HTTP app sets placeholders that are only available in areas of the config related to handling HTTP requests.

The following placeholders are always available:

Placeholder Description
{env.*} Environment variable (example: {env.HOME})
{system.hostname} The system's local hostname
{system.slash} The system's filepath separator
{system.os} The system's OS
{system.arch} The system's architecture
{time.now.common_log} The current timestamp in Common Log Format

Not all config fields support placeholders, but most do where you would expect it.

File locations

This section contains information about where to find various files. File and directory paths described here are defaults at best; some can be overridden.

Your config files

There is no single, conventional place for you to put your config files. Put them wherever makes the most sense to you.

Distributions that ship with a default config file should document where this config file is at, even if it might be obvious to the package/distro maintainers.

Data directory

Caddy stores TLS certificates and other important assets in a data directory.

If the XDG_DATA_HOME environment variable is set, it is $XDG_DATA_HOME/caddy.

Otherwise, its path varies by platform, adhering to OS conventions:

OS Data directory path
Linux, BSD $HOME/.local/share/caddy
Windows %AppData%\Caddy
macOS $HOME/Library/Application Support/Caddy
Plan 9 $HOME/lib/caddy
Android $HOME/caddy (or /sdcard/caddy)

The data directory must not be treated like a cache. Its contents are not ephemeral or merely for the sake of performance. Caddy stores TLS certificates, private keys, OCSP staples, and other necessary information to the data directory. It should not be purged without an understanding of the implications.

It is crucial that this directory is persistent and writeable by Caddy.

Configuration directory

This is where Caddy may store certain configuration to disk. Most notably, it persists the last active configuration (by default) to this folder for easy resumption later using caddy run --resume.

If the XDG_CONFIG_HOME environment variable is set, it is $XDG_CONFIG_HOME/caddy.

Otherwise, its path varies by platform, adhering to OS conventions:

OS Config directory path
Linux, BSD $HOME/.config/caddy
Windows %AppData%\Caddy
macOS $HOME/Library/Application Support/Caddy
Plan 9 $HOME/lib/caddy

It is crucial that this directory is persistent and writeable by Caddy.

Durations

Duration strings are commonly used throughout Caddy's configuration. They take on the same format as Go's time.ParseDuration syntax. Valid units are:

  • ns (nanosecond)
  • us/µs (microsecond)
  • ms (millisecond)
  • s (second)
  • m (minute)
  • h (hour)

Examples:

  • 250ms
  • 5s
  • 1.5h
  • 2h45m

In the JSON config, duration values can also be integers which represents nanoseconds.