Home

Caddyfile

Caddyfile is the configuration file format used by the Caddy web server. It provides a human-friendly way to define site blocks, server behavior, and options. Caddy can read a Caddyfile directly or convert it to JSON for production deployments.

The basic structure consists of blocks. A site block starts with a label, usually a hostname such

Common directives configure core capabilities. root sets the document root, file_server enables static file serving, and

Example:

example.com {

root * /var/www/html

file_server

log {

output file /var/log/caddy/access.log

}

reverse_proxy localhost:8080

}

Usage notes: the Caddyfile is named Caddyfile by convention and located in the server’s working directory

as
example.com
or
an
address
like
:80
or
:443,
followed
by
curly-braced
directives
that
configure
that
site.
Inside
a
block,
directives
are
written
on
separate
lines
and
may
take
arguments.
A
global
or
top-level
block,
written
as
a
bare
set
of
braces
{},
holds
options
that
apply
to
the
whole
server.
Comments
begin
with
#.
reverse_proxy
forwards
requests
to
another
service.
tls
configures
certificates
and
enables
automatic
TLS
via
ACME
by
default.
log
defines
access
logging,
while
redir
and
rewrite
handle
URL
redirection
and
rewriting.
header
edits
response
headers,
and
respond
can
generate
inline
responses.
The
encode
directive
enables
compression
or
streaming
features.
Many
directives
are
implemented
as
plugins
and
can
extend
functionality.
or
a
specified
path.
It
supports
imports
and
plugins
to
extend
capabilities.
Caddy
can
also
run
with
a
JSON
configuration,
with
the
Caddyfile
serving
as
a
convenient,
readable
alternative.