docs: Add Caddyfile syntax highlighting (#41)

This commit is contained in:
Francis Lavoie 2020-05-17 16:32:12 -04:00 committed by GitHub
parent 75fcfc21bb
commit e0f5ee1bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 215 additions and 179 deletions

View file

@ -27,7 +27,7 @@ Create a new text file named `Caddyfile` (no extension).
The first thing you should type is your site's [address](/docs/caddyfile/concepts#addresses): The first thing you should type is your site's [address](/docs/caddyfile/concepts#addresses):
``` ```caddy
localhost localhost
``` ```
@ -37,7 +37,7 @@ localhost
Then hit enter and type what you want it to do. For this tutorial, make your Caddyfile look like this: Then hit enter and type what you want it to do. For this tutorial, make your Caddyfile look like this:
``` ```caddy
localhost localhost
respond "Hello, world!" respond "Hello, world!"
@ -63,7 +63,7 @@ Open [localhost](https://localhost) in your browser and see your web server work
That's not particularly exciting, so let's change our static response to a [file server](/docs/caddyfile/directives/file_server) with directory listings enabled: That's not particularly exciting, so let's change our static response to a [file server](/docs/caddyfile/directives/file_server) with directory listings enabled:
``` ```caddy
localhost localhost
file_server browse file_server browse
@ -99,7 +99,7 @@ Page loaded at: {{`{{`}}now | date "Mon Jan 2 15:04:05 MST 2006"{{`}}`}}
Wait a minute. We should see today's date. Why didn't it work? It's because the server hasn't yet been configured to evaluate templates! Easy to fix, just add a line to the Caddyfile so it looks like this: Wait a minute. We should see today's date. Why didn't it work? It's because the server hasn't yet been configured to evaluate templates! Easy to fix, just add a line to the Caddyfile so it looks like this:
``` ```caddy
localhost localhost
templates templates
@ -118,7 +118,7 @@ With Caddy's [templates module](/docs/modules/http.handlers.templates), you can
It's good practice to compress responses with a quick and modern compression algorithm. Let's enable Gzip and Zstandard support using the [`encode`](/docs/caddyfile/directives/encode) directive: It's good practice to compress responses with a quick and modern compression algorithm. Let's enable Gzip and Zstandard support using the [`encode`](/docs/caddyfile/directives/encode) directive:
``` ```caddy
localhost localhost
encode zstd gzip encode zstd gzip
@ -143,7 +143,7 @@ But it is easy to make it so we can add more sites!
Our Caddyfile so far: Our Caddyfile so far:
``` ```caddy
localhost localhost
encode zstd gzip encode zstd gzip
@ -153,7 +153,7 @@ file_server browse
is equivalent to this one: is equivalent to this one:
``` ```caddy
localhost { localhost {
encode zstd gzip encode zstd gzip
templates templates
@ -167,7 +167,7 @@ By wrapping our site block in curly braces `{ }` we are able to define multiple,
For example: For example:
``` ```caddy
:8080 { :8080 {
respond "I am 8080" respond "I am 8080"
} }
@ -181,7 +181,7 @@ When wrapping site blocks in curly braces, only [addresses](/docs/caddyfile/conc
For multiple sites which share the same configuration, you can add more addresses, for example: For multiple sites which share the same configuration, you can add more addresses, for example:
``` ```caddy
:8080, :8081 { :8080, :8081 {
... ...
} }
@ -198,7 +198,7 @@ We may want to apply some directives only to certain requests. For example, let'
This config will not work like we want: This config will not work like we want:
``` ```caddy
localhost localhost
file_server file_server
@ -207,7 +207,7 @@ reverse_proxy 127.0.0.1:9005
In practice, we may want to use the reverse proxy only for API requests, i.e. requests with a base path of `/api/`. This is easy to do by adding a [matcher token](/docs/caddyfile/matchers#syntax): In practice, we may want to use the reverse proxy only for API requests, i.e. requests with a base path of `/api/`. This is easy to do by adding a [matcher token](/docs/caddyfile/matchers#syntax):
``` ```caddy
localhost localhost
file_server file_server
@ -232,7 +232,7 @@ First, set an environment variable (in the same shell that runs Caddy):
Then you can use it like this in the Caddyfile: Then you can use it like this in the Caddyfile:
``` ```caddy
{$SITE_ADDRESS} {$SITE_ADDRESS}
file_server file_server
@ -240,7 +240,7 @@ file_server
Before the Caddyfile is parsed, it will be expanded to: Before the Caddyfile is parsed, it will be expanded to:
``` ```caddy
localhost:9055 localhost:9055
file_server file_server
@ -255,7 +255,7 @@ You can use environment variables anywhere in the Caddyfile, for any number of t
One last thing that you will find most helpful: if you want to remark or note anything in your Caddyfile, you can use comments, starting with `#`: One last thing that you will find most helpful: if you want to remark or note anything in your Caddyfile, you can use comments, starting with `#`:
``` ```caddy
# this starts a comment # this starts a comment
``` ```

View file

@ -8,7 +8,7 @@ The **Caddyfile** is a convenient Caddy configuration format for humans. It is m
It looks like this: It looks like this:
``` ```caddy
example.com example.com
root * /var/www/wordpress root * /var/www/wordpress

View file

@ -46,7 +46,7 @@ Opening and closing a **block** is done with curly braces:
When there is only one site block, the curly braces (and indentation) are optional. This is for convenience to quickly define a single site, for example, this: When there is only one site block, the curly braces (and indentation) are optional. This is for convenience to quickly define a single site, for example, this:
``` ```caddy
localhost localhost
reverse_proxy /api/* localhost:9001 reverse_proxy /api/* localhost:9001
@ -55,7 +55,7 @@ file_server
is equivalent to: is equivalent to:
``` ```caddy
localhost { localhost {
reverse_proxy /api/* localhost:9001 reverse_proxy /api/* localhost:9001
file_server file_server
@ -66,7 +66,7 @@ when you have only a single site block; it's a matter of preference.
To configure multiple sites with the same Caddyfile, you **must** use curly braces around each one to separate their configurations: To configure multiple sites with the same Caddyfile, you **must** use curly braces around each one to separate their configurations:
``` ```caddy
example1.com { example1.com {
root * /www/example.com root * /www/example.com
file_server file_server
@ -84,7 +84,7 @@ If a request matches multiple site blocks, the site block with the most specific
**Directives** are keywords which customize how the site is served. For example, a complete file server config might look like this: **Directives** are keywords which customize how the site is served. For example, a complete file server config might look like this:
``` ```caddy
localhost localhost
file_server file_server
@ -92,7 +92,7 @@ file_server
Or a reverse proxy: Or a reverse proxy:
``` ```caddy
localhost localhost
reverse_proxy localhost:9000 reverse_proxy localhost:9000
@ -104,7 +104,7 @@ In the second example, `localhost:9000` is an **argument** because it appears on
**Subdirectives** can appear in directive blocks: **Subdirectives** can appear in directive blocks:
``` ```caddy
localhost localhost
reverse_proxy localhost:9000 localhost:9001 { reverse_proxy localhost:9000 localhost:9001 {
@ -121,7 +121,7 @@ The Caddyfile is lexed into tokens before being parsed. Whitespace is significan
Often, directives expect a certain number of arguments; if a single argument has a value with whitespace, it would be lexed as two separate tokens: Often, directives expect a certain number of arguments; if a single argument has a value with whitespace, it would be lexed as two separate tokens:
``` ```caddy-d
directive abc def directive abc def
``` ```
@ -129,13 +129,13 @@ This could be problematic and return errors or unexpected behavior.
If `abc def` is supposed to be the value of a single argument, it needs to be quoted: If `abc def` is supposed to be the value of a single argument, it needs to be quoted:
``` ```caddy-d
directive "abc def" directive "abc def"
``` ```
Quotes can be escaped if you need to use quotes in quoted tokens, too: Quotes can be escaped if you need to use quotes in quoted tokens, too:
``` ```caddy-d
directive "\"abc def\"" directive "\"abc def\""
``` ```
@ -172,13 +172,13 @@ Wildcards (`*`) may be used, but only to represent precisely one label of the ho
If multiple sites share the same definition, you can list all of them together: If multiple sites share the same definition, you can list all of them together:
``` ```caddy
localhost:8080, example.com, www.example.com localhost:8080, example.com, www.example.com
``` ```
or or
``` ```caddy
localhost:8080, localhost:8080,
example.com, example.com,
www.example.com www.example.com
@ -198,7 +198,7 @@ Request matchers can be used to classify requests by a given criteria. This conc
For directives that support matchers, the first argument after the directive is the **matcher token**. Here are some examples: For directives that support matchers, the first argument after the directive is the **matcher token**. Here are some examples:
``` ```caddy-d
root * /var/www # matcher token: * root * /var/www # matcher token: *
root /index.html /var/www # matcher token: /index.html root /index.html /var/www # matcher token: /index.html
root @post /var/www # matcher token: @post root @post /var/www # matcher token: @post
@ -241,7 +241,7 @@ You can use any [Caddy placeholders](/docs/conventions#placeholders) in the Cadd
You can define special blocks called snippets by giving them a name surrounded in parentheses: You can define special blocks called snippets by giving them a name surrounded in parentheses:
``` ```caddy
(redirect) { (redirect) {
@http { @http {
scheme http scheme http
@ -252,7 +252,7 @@ You can define special blocks called snippets by giving them a name surrounded i
And then you can reuse this anywhere you need: And then you can reuse this anywhere you need:
``` ```caddy-d
import redirect import redirect
``` ```
@ -264,7 +264,7 @@ The `import` directive can also be used to include other files in its place. As
Comments start with `#` and proceed until the end of the line: Comments start with `#` and proceed until the end of the line:
``` ```caddy-d
# Comments can start a line # Comments can start a line
directive # or go at the end directive # or go at the end
``` ```
@ -276,7 +276,7 @@ The hash character `#` cannot appear in the middle of a token (i.e. it must be p
If your configuration relies on environment variables, you can use them in the Caddyfile: If your configuration relies on environment variables, you can use them in the Caddyfile:
``` ```caddy
{$SITE_ADDRESS} {$SITE_ADDRESS}
``` ```
@ -289,7 +289,7 @@ If you want to defer the substitution of an environment variable until runtime,
A Caddyfile may optionally start with a special block that has no keys, called a [global options block](/docs/caddyfile/options): A Caddyfile may optionally start with a special block that has no keys, called a [global options block](/docs/caddyfile/options):
``` ```caddy
{ {
... ...
} }

View file

@ -35,7 +35,7 @@ Directive | Description
The syntax of each directive will look something like this: The syntax of each directive will look something like this:
``` ```caddy-d
directive [<matcher>] <args...> { directive [<matcher>] <args...> {
subdirective [<args...>] subdirective [<args...>]
} }
@ -54,7 +54,7 @@ Subdirectives are always optional unless documented otherwise, even though they
Most---but not all---directives accept [matcher tokens](/docs/caddyfile/matchers#syntax), which let you filter requests. Matcher tokens are usually optional. If you see this in a directive's syntax: Most---but not all---directives accept [matcher tokens](/docs/caddyfile/matchers#syntax), which let you filter requests. Matcher tokens are usually optional. If you see this in a directive's syntax:
``` ```caddy-d
[<matcher>] [<matcher>]
``` ```
@ -67,7 +67,7 @@ Because matcher tokens all work the same, the various possibilities for the matc
Many directives manipulate the HTTP handler chain. The order in which those directives are evaluated matters, so a default ordering is hard-coded into Caddy: Many directives manipulate the HTTP handler chain. The order in which those directives are evaluated matters, so a default ordering is hard-coded into Caddy:
``` ```caddy-d
root root
header header

View file

@ -15,7 +15,7 @@ Caddy configuration does not accept plaintext passwords; you MUST hash them befo
## Syntax ## Syntax
``` ```caddy-d
basicauth [<matcher>] [<hash_algorithm>] { basicauth [<matcher>] [<hash_algorithm>] {
<username> <hashed_password_base64> [<salt_base64>] <username> <hashed_password_base64> [<salt_base64>]
... ...
@ -32,7 +32,7 @@ basicauth [<matcher>] [<hash_algorithm>] {
Protect all resources in /secret so only Bob can access them with the password "hiccup": Protect all resources in /secret so only Bob can access them with the password "hiccup":
``` ```caddy-d
basicauth /secret/* { basicauth /secret/* {
Bob JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX Bob JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX
} }

View file

@ -11,7 +11,7 @@ Note that binding sites inconsistently may result in unintended consequences. Fo
## Syntax ## Syntax
``` ```caddy-d
bind <hosts...> bind <hosts...>
``` ```
@ -22,12 +22,12 @@ bind <hosts...>
To make a socket accessible only on the current machine, bind to the loopback interface (localhost): To make a socket accessible only on the current machine, bind to the loopback interface (localhost):
``` ```caddy-d
bind 127.0.0.1 bind 127.0.0.1
``` ```
To include IPv6: To include IPv6:
``` ```caddy-d
bind 127.0.0.1 ::1 bind 127.0.0.1 ::1
``` ```

View file

@ -8,7 +8,7 @@ Encodes responses using the configured encoding(s). A typical use for encoding i
## Syntax ## Syntax
``` ```caddy-d
encode [<matcher>] <formats...> { encode [<matcher>] <formats...> {
gzip [<level>] gzip [<level>]
zstd zstd
@ -24,13 +24,13 @@ encode [<matcher>] <formats...> {
Enable Gzip compression: Enable Gzip compression:
``` ```caddy-d
encode gzip encode gzip
``` ```
Enable Zstandard and Gzip compression: Enable Zstandard and Gzip compression:
``` ```caddy-d
encode zstd gzip encode zstd gzip
``` ```

View file

@ -9,7 +9,7 @@ A static file server. It works by appending the request's URI path to the [site'
## Syntax ## Syntax
``` ```caddy-d
file_server [<matcher>] [browse] { file_server [<matcher>] [browse] {
root <path> root <path>
hide <files...> hide <files...>
@ -29,18 +29,18 @@ file_server [<matcher>] [browse] {
A static file server out of the current directory: A static file server out of the current directory:
``` ```caddy-d
file_server file_server
``` ```
With file listings enabled: With file listings enabled:
``` ```caddy-d
file_server browse file_server browse
``` ```
Only serve static files out of the `/static` folder: Only serve static files out of the `/static` folder:
``` ```caddy-d
file_server /static/* file_server /static/*
``` ```

View file

@ -10,7 +10,7 @@ The `handle` directive is kind of similar to the `location` directive from nginx
## Syntax ## Syntax
``` ```caddy-d
handle [<matcher>] { handle [<matcher>] {
<directives...> <directives...>
} }
@ -27,7 +27,7 @@ If you prefer crafting HTTP handler logic in a more inheritence-based way like n
Handle requests in `/foo/` by the static file server, and send all other requests to the reverse proxy: Handle requests in `/foo/` by the static file server, and send all other requests to the reverse proxy:
``` ```caddy-d
handle /foo/* { handle /foo/* {
file_server file_server
} }

View file

@ -10,7 +10,7 @@ When the normal HTTP request handlers return an error, normal procesing stops an
## Syntax ## Syntax
``` ```caddy-d
handle_errors { handle_errors {
<directives...> <directives...>
} }

View file

@ -11,7 +11,7 @@ By default, header operations are performed immediately unless any of the header
## Syntax ## Syntax
``` ```caddy-d
header [<matcher>] [[+|-]<field> [<value>|<find>] [<replace>]] { header [<matcher>] [[+|-]<field> [<value>|<find>] [<replace>]] {
<field> <find> <replace> <field> <find> <replace>
[+]<field> <value> [+]<field> <value>
@ -33,25 +33,25 @@ For multiple header manipulations, you can open a block and specify one manipula
Set a custom header field on all requests: Set a custom header field on all requests:
``` ```caddy-d
header Custom-Header "My value" header Custom-Header "My value"
``` ```
Strip the "Hidden" header field: Strip the "Hidden" header field:
``` ```caddy-d
header -Hidden header -Hidden
``` ```
Replace `http://` with `https://` in any Location header: Replace `http://` with `https://` in any Location header:
``` ```caddy-d
header Location http:// https:// header Location http:// https://
``` ```
Set security headers on all pages: (**WARNING:** only use if you understand the implications!) Set security headers on all pages: (**WARNING:** only use if you understand the implications!)
``` ```caddy-d
header { header {
# enable HSTS # enable HSTS
Strict-Transport-Security max-age=31536000; Strict-Transport-Security max-age=31536000;
@ -69,7 +69,7 @@ header {
Multiple header directives that are intended to be mutually-exclusive: Multiple header directives that are intended to be mutually-exclusive:
``` ```caddy-d
route { route {
header Cache-Control max=age=3600 header Cache-Control max=age=3600
header /static/* Cache-Control max-age=31536000 header /static/* Cache-Control max-age=31536000

View file

@ -10,7 +10,7 @@ This directive is a special case: it is evaluated before the structure is parsed
## Syntax ## Syntax
``` ```caddy-d
import <pattern> import <pattern>
``` ```
@ -21,6 +21,6 @@ import <pattern>
Import all files in an adjacent sites-enabled folder: Import all files in an adjacent sites-enabled folder:
``` ```caddy-d
import sites-enabled/* import sites-enabled/*
``` ```

View file

@ -8,7 +8,7 @@ Enables and configures HTTP request logging (also known as access logs).
## Syntax ## Syntax
``` ```caddy-d
log { log {
output <writer_module> ... output <writer_module> ...
format <encoder_module> ... format <encoder_module> ...
@ -28,7 +28,7 @@ The **output** subdirective lets you customize where logs get written. It appear
Standard error (console, default). Standard error (console, default).
``` ```caddy-d
output stderr output stderr
``` ```
@ -36,7 +36,7 @@ output stderr
Standard output (console). Standard output (console).
``` ```caddy-d
output stdout output stdout
``` ```
@ -44,7 +44,7 @@ output stdout
No output. No output.
``` ```caddy-d
output discard output discard
``` ```
@ -52,7 +52,7 @@ output discard
A file. By default, log files are rotated ("rolled") to prevent disk space exhaustion. A file. By default, log files are rotated ("rolled") to prevent disk space exhaustion.
``` ```caddy-d
output file <filename> { output file <filename> {
roll_disabled roll_disabled
roll_size <size> roll_size <size>
@ -72,7 +72,7 @@ output file <filename> {
A network socket. A network socket.
``` ```caddy-d
output net <address> output net <address>
``` ```
@ -86,8 +86,8 @@ The **format** subdirective lets you customize how logs get encoded (formatted).
In addition to the syntax for each individual encoder, these common properties can be set on most encoders: In addition to the syntax for each individual encoder, these common properties can be set on most encoders:
``` ```caddy-d
{ format <encoder_module> {
message_key <key> message_key <key>
level_key <key> level_key <key>
time_key <key> time_key <key>
@ -114,7 +114,7 @@ In addition to the syntax for each individual encoder, these common properties c
The console encoder formats the log entry for human readability while preserving some structure. The console encoder formats the log entry for human readability while preserving some structure.
``` ```caddy-d
format console format console
``` ```
@ -122,7 +122,7 @@ format console
Formats each log entry as a JSON object. Formats each log entry as a JSON object.
``` ```caddy-d
format json format json
``` ```
@ -130,7 +130,7 @@ format json
Formats each log entry as [logfmt](https://brandur.org/logfmt). Formats each log entry as [logfmt](https://brandur.org/logfmt).
``` ```caddy-d
format logfmt format logfmt
``` ```
@ -138,7 +138,7 @@ format logfmt
Writes only a single field from the structure log entry. Useful if one of the fields has all the information you need. Writes only a single field from the structure log entry. Useful if one of the fields has all the information you need.
``` ```caddy-d
format single_field <field_name> format single_field <field_name>
``` ```
@ -154,13 +154,13 @@ format single_field <field_name>
Enable access logging (to the console): Enable access logging (to the console):
``` ```caddy-d
log log
``` ```
Write logs to a file (with log rolling, which is enabled by default): Write logs to a file (with log rolling, which is enabled by default):
``` ```caddy-d
log { log {
output file /var/log/access.log output file /var/log/access.log
} }
@ -168,7 +168,7 @@ log {
Customize log rolling: Customize log rolling:
``` ```caddy-d
log { log {
output file /var/log/access.log { output file /var/log/access.log {
roll_size 1gb roll_size 1gb
@ -180,7 +180,7 @@ log {
Use common log format (deprecated, but can be useful for older setups): Use common log format (deprecated, but can be useful for older setups):
``` ```caddy-d
log { log {
format single_field common_log format single_field common_log
} }

View file

@ -13,7 +13,7 @@ It expects that any `index.php` at the site root acts as a router. If that is no
## Syntax ## Syntax
``` ```caddy-d
php_fastcgi [<matcher>] <php-fpm_gateway> php_fastcgi [<matcher>] <php-fpm_gateway>
``` ```
@ -26,7 +26,7 @@ Since this directive is an opinionated wrapper over a reverse proxy, you can ope
The `php_fastcgi` directive is the same as the following configuration: The `php_fastcgi` directive is the same as the following configuration:
``` ```caddy-d
route { route {
# Add trailing slash for directory requests # Add trailing slash for directory requests
@canonicalPath { @canonicalPath {
@ -64,18 +64,18 @@ Most modern PHP apps work well with this preset. If yours does not, feel free to
Proxy all PHP requests to a FastCGI responder listening at 127.0.0.1:9000: Proxy all PHP requests to a FastCGI responder listening at 127.0.0.1:9000:
``` ```caddy-d
php_fastcgi 127.0.0.1:9000 php_fastcgi 127.0.0.1:9000
``` ```
Same, but only for requests under `/blog/`: Same, but only for requests under `/blog/`:
``` ```caddy-d
php_fastcgi /blog/* 127.0.0.1:9000 php_fastcgi /blog/* 127.0.0.1:9000
``` ```
When using php-fpm listening via a unix socket: When using php-fpm listening via a unix socket:
``` ```caddy-d
php_fastcgi unix//run/php/php7.4-fpm.sock php_fastcgi unix//run/php/php7.4-fpm.sock
``` ```

View file

@ -11,7 +11,7 @@ This directive implies that a matched request is to be rejected. It is ordered v
## Syntax ## Syntax
``` ```caddy-d
redir [<matcher>] <to> [<code>] redir [<matcher>] <to> [<code>]
``` ```
@ -28,18 +28,18 @@ redir [<matcher>] <to> [<code>]
Redirect all requests to `https://example.com`: Redirect all requests to `https://example.com`:
``` ```caddy-d
redir https://example.com redir https://example.com
``` ```
Same, but preserve the existing URI: Same, but preserve the existing URI:
``` ```caddy-d
redir https://example.com{uri} redir https://example.com{uri}
``` ```
Same, but permanent: Same, but permanent:
``` ```caddy-d
redir https://example.com{uri} permanent redir https://example.com{uri} permanent
``` ```

View file

@ -9,7 +9,7 @@ Manipulates HTTP header fields on the request. It can set, add, and delete heade
## Syntax ## Syntax
``` ```caddy-d
request_header [<matcher>] [[+|-]<field> [<value>|<find>] [<replace>]] request_header [<matcher>] [[+|-]<field> [<value>|<find>] [<replace>]]
``` ```
@ -23,6 +23,6 @@ request_header [<matcher>] [[+|-]<field> [<value>|<find>] [<replace>]]
Remove the Referer header from the request: Remove the Referer header from the request:
``` ```caddy-d
request_header -Referer request_header -Referer
``` ```

View file

@ -9,7 +9,7 @@ Writes a hard-coded/static response to the client.
## Syntax ## Syntax
``` ```caddy-d
respond [<matcher>] <status>|<body> [<status>] { respond [<matcher>] <status>|<body> [<status>] {
body <text> body <text>
close close
@ -32,19 +32,19 @@ To clarify, the first non-matcher argument can be either a 3-digit status code o
Write a 200 status with an empty body to all health checks: Write a 200 status with an empty body to all health checks:
``` ```caddy-d
respond /health-check 200 respond /health-check 200
``` ```
Write a simple response body to all requests: Write a simple response body to all requests:
``` ```caddy-d
respond "Hello, world!" respond "Hello, world!"
``` ```
Write an error response and close the connection: Write an error response and close the connection:
``` ```caddy-d
respond /secret/* "Access denied" 403 { respond /secret/* "Access denied" 403 {
close close
} }

View file

@ -9,7 +9,7 @@ Proxies requests to one or more backends with configurable transport, load balan
## Syntax ## Syntax
``` ```caddy-d
reverse_proxy [<matcher>] [<upstreams...>] { reverse_proxy [<matcher>] [<upstreams...>] {
# backends # backends
to <upstreams...> to <upstreams...>
@ -118,7 +118,7 @@ Caddy's proxy **transport** is pluggable:
The `http` transport can look like this: The `http` transport can look like this:
``` ```caddy-d
transport http { transport http {
read_buffer <size> read_buffer <size>
write_buffer <size> write_buffer <size>
@ -146,7 +146,7 @@ transport http {
The `fastcgi` transport can look like this: The `fastcgi` transport can look like this:
``` ```caddy-d
transport fastcgi { transport fastcgi {
root <path> root <path>
split <at> split <at>
@ -163,19 +163,19 @@ transport fastcgi {
Reverse proxy all requests to a local backend: Reverse proxy all requests to a local backend:
``` ```caddy-d
reverse_proxy localhost:9005 reverse_proxy localhost:9005
``` ```
Load-balance all requests between 3 backends: Load-balance all requests between 3 backends:
``` ```caddy-d
reverse_proxy node1:80 node2:80 node3:80 reverse_proxy node1:80 node2:80 node3:80
``` ```
Same, but only requests within `/api`, and with header affinity: Same, but only requests within `/api`, and with header affinity:
``` ```caddy-d
reverse_proxy /api/* node1:80 node2:80 node3:80 { reverse_proxy /api/* node1:80 node2:80 node3:80 {
lb_policy header X-My-Header lb_policy header X-My-Header
} }
@ -183,7 +183,7 @@ reverse_proxy /api/* node1:80 node2:80 node3:80 {
Set the upstream Host header to the address of the upstream (by default, it will retain its original, incoming value): Set the upstream Host header to the address of the upstream (by default, it will retain its original, incoming value):
``` ```caddy-d
reverse_proxy localhost:9000 { reverse_proxy localhost:9000 {
header_up Host {http.reverse_proxy.upstream.hostport} header_up Host {http.reverse_proxy.upstream.hostport}
} }
@ -191,13 +191,13 @@ reverse_proxy localhost:9000 {
Reverse proxy to an HTTPS endpoint: Reverse proxy to an HTTPS endpoint:
``` ```caddy-d
reverse_proxy https://example.com reverse_proxy https://example.com
``` ```
Strip a path prefix then proxy: Strip a path prefix then proxy:
``` ```caddy-d
route /prefix/* { route /prefix/* {
uri strip_prefix /prefix uri strip_prefix /prefix
reverse_proxy localhost:9000 reverse_proxy localhost:9000

View file

@ -13,7 +13,7 @@ Because `rewrite` essentially performs an internal redirect, the Caddyfile adapt
## Syntax ## Syntax
``` ```caddy-d
rewrite [<matcher>] <to> rewrite [<matcher>] <to>
``` ```
@ -24,25 +24,25 @@ rewrite [<matcher>] <to>
Rewrite all requests to `foo.html`, leaving any query string unchanged: Rewrite all requests to `foo.html`, leaving any query string unchanged:
``` ```caddy-d
rewrite * /foo.html rewrite * /foo.html
``` ```
Replace the query string on API requests with `a=b`, leaving the path unchanged: Replace the query string on API requests with `a=b`, leaving the path unchanged:
``` ```caddy-d
rewrite /api/* ?a=b rewrite /api/* ?a=b
``` ```
Preserve the existing query string and add a key-value pair: Preserve the existing query string and add a key-value pair:
``` ```caddy-d
rewrite /api/* ?{query}&a=b rewrite /api/* ?{query}&a=b
``` ```
Change both the path and query string, preserving the original query string while adding the original path as the `p` parameter: Change both the path and query string, preserving the original query string while adding the original path as the `p` parameter:
``` ```caddy-d
rewrite * /index.php?{query}&p={path} rewrite * /index.php?{query}&p={path}
``` ```

View file

@ -11,7 +11,7 @@ Specifically, this directive sets the `{http.vars.root}` placeholder. It is mutu
## Syntax ## Syntax
``` ```caddy-d
root [<matcher>] <path> root [<matcher>] <path>
``` ```
@ -23,7 +23,7 @@ Note that a matcher token is usually required since the first argument is a path
Set the site root to `/home/user/public_html` for all requests: Set the site root to `/home/user/public_html` for all requests:
``` ```caddy-d
root * /home/user/public_html root * /home/user/public_html
``` ```
@ -31,7 +31,7 @@ root * /home/user/public_html
Set the site root to `public_html` (relative to current working directory) for all requests: Set the site root to `public_html` (relative to current working directory) for all requests:
``` ```caddy-d
root public_html root public_html
``` ```
@ -39,6 +39,6 @@ root public_html
Set the site root only for requests in `/foo`: Set the site root only for requests in `/foo`:
``` ```caddy-d
root /foo/* /home/user/public_html/foo root /foo/* /home/user/public_html/foo
``` ```

View file

@ -13,7 +13,7 @@ This directive is a special case in that its subdirectives are also regular dire
## Syntax ## Syntax
``` ```caddy-d
route [<matcher>] { route [<matcher>] {
<directives...> <directives...>
} }
@ -37,7 +37,7 @@ However, there may be occasions where the second directive (`redir`) has a more
So you might try a Caddyfile like this (but this will not work as expected!): So you might try a Caddyfile like this (but this will not work as expected!):
``` ```caddy
example.com example.com
file_server /specific.html file_server /specific.html
@ -48,7 +48,7 @@ The problem is that, internally, `redir` comes before `file_server`, but in this
Fortunately, the solution is easy: just wrap those two directives in a `route` block: Fortunately, the solution is easy: just wrap those two directives in a `route` block:
``` ```caddy
example.com example.com
route { route {
@ -68,7 +68,7 @@ And now `file_server` will be chained in before `redir` because the order is tak
Strip `/api` prefix from request path just before proxying all API requests to a backend: Strip `/api` prefix from request path just before proxying all API requests to a backend:
``` ```caddy-d
route /api/* { route /api/* {
uri strip_prefix /api uri strip_prefix /api
reverse_proxy localhost:9000 reverse_proxy localhost:9000

View file

@ -9,7 +9,7 @@ Executes the response body as a [template](/docs/modules/http.handlers.templates
## Syntax ## Syntax
``` ```caddy-d
templates [<matcher>] { templates [<matcher>] {
mime <types...> mime <types...>
between <open_delim> <close_delim> between <open_delim> <close_delim>
@ -26,7 +26,7 @@ templates [<matcher>] {
Enable templates on all requests: Enable templates on all requests:
``` ```caddy-d
templates templates
``` ```

View file

@ -13,7 +13,7 @@ Compatibility note: Due to its sensitive nature as a security protocol, delibera
## Syntax ## Syntax
``` ```caddy-d
tls [internal|<email>] | [<cert_file> <key_file>] { tls [internal|<email>] | [<cert_file> <key_file>] {
protocols <min> [<max>] protocols <min> [<max>]
ciphers <cipher_suites...> ciphers <cipher_suites...>
@ -69,19 +69,19 @@ tls [internal|<email>] | [<cert_file> <key_file>] {
Use a custom certificate and key: Use a custom certificate and key:
``` ```caddy-d
tls cert.pem key.pem tls cert.pem key.pem
``` ```
Use locally-trusted certificates for all hosts on the current site block, rather than public certificates via ACME / Let's Encrypt (useful in dev environments): Use locally-trusted certificates for all hosts on the current site block, rather than public certificates via ACME / Let's Encrypt (useful in dev environments):
``` ```caddy-d
tls internal tls internal
``` ```
Use locally-trusted certificates, but managed on-demand intead of in the background: Use locally-trusted certificates, but managed on-demand intead of in the background:
``` ```caddy-d
tls internal { tls internal {
on_demand on_demand
} }
@ -89,13 +89,13 @@ tls internal {
Specify an email address for your ACME account (but if only one email is used for all sites, we recommend the `email` [global option](/docs/caddyfile/options) instead): Specify an email address for your ACME account (but if only one email is used for all sites, we recommend the `email` [global option](/docs/caddyfile/options) instead):
``` ```caddy-d
tls your@email.com tls your@email.com
``` ```
Enable the DNS challenge for a domain managed on Cloudflare with account credentials in an environment variable: Enable the DNS challenge for a domain managed on Cloudflare with account credentials in an environment variable:
``` ```caddy-d
tls { tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN} dns cloudflare {env.CLOUDFLARE_API_TOKEN}
} }

View file

@ -9,7 +9,7 @@ Rewrites the request URI path to the first of the listed files which exists in t
## Syntax ## Syntax
``` ```caddy-d
try_files <files...> try_files <files...>
``` ```
@ -20,7 +20,7 @@ try_files <files...>
The `try_files` directive is basically a shortcut for: The `try_files` directive is basically a shortcut for:
``` ```caddy-d
@try_files { @try_files {
file { file {
try_files <files...> try_files <files...>
@ -36,18 +36,18 @@ Note that this directive does not accept a matcher token. If you need more compl
If the request does not match any static files, rewrite to an index/router file: If the request does not match any static files, rewrite to an index/router file:
``` ```caddy-d
try_files {path} /index.php try_files {path} /index.php
``` ```
Same, but adding the original path to the query string: Same, but adding the original path to the query string:
``` ```caddy-d
try_files {path} /index.php?{query}&p={path} try_files {path} /index.php?{query}&p={path}
``` ```
Same, but also match directories: Same, but also match directories:
``` ```caddy-d
try_files {path} {path}/ /index.php?{query}&p={path} try_files {path} {path}/ /index.php?{query}&p={path}
``` ```

View file

@ -11,7 +11,7 @@ This directive is distinct from [`rewrite`](rewrite) in that `uri` _partially_ c
## Syntax ## Syntax
``` ```caddy-d
uri [<matcher>] strip_prefix|strip_suffix|replace \ uri [<matcher>] strip_prefix|strip_suffix|replace \
<target> \ <target> \
[<replacement> [<limit>]] [<replacement> [<limit>]]
@ -30,18 +30,18 @@ uri [<matcher>] strip_prefix|strip_suffix|replace \
Strip `/api` from the beginning of all request paths: Strip `/api` from the beginning of all request paths:
``` ```caddy-d
uri strip_prefix /api uri strip_prefix /api
``` ```
Strip `.php` from the end of all request paths: Strip `.php` from the end of all request paths:
``` ```caddy-d
uri strip_suffix .php uri strip_suffix .php
``` ```
Replace "/docs/" with "/v1/docs/" in any request URI: Replace "/docs/" with "/v1/docs/" in any request URI:
``` ```caddy-d
uri replace /docs/ /v1/docs/ uri replace /docs/ /v1/docs/
``` ```

View file

@ -31,25 +31,25 @@ Matcher tokens are [usually optional](/docs/caddyfile/directives#matchers). If a
This directive applies to [all](#wildcard-matchers) HTTP requests: This directive applies to [all](#wildcard-matchers) HTTP requests:
``` ```caddy-d
reverse_proxy localhost:9000 reverse_proxy localhost:9000
``` ```
And this is the same: And this is the same:
``` ```caddy-d
reverse_proxy * localhost:9000 reverse_proxy * localhost:9000
``` ```
But this directive applies only to requests having a [path](#path-matchers) starting with `/api/`: But this directive applies only to requests having a [path](#path-matchers) starting with `/api/`:
``` ```caddy-d
reverse_proxy /api/* localhost:9000 reverse_proxy /api/* localhost:9000
``` ```
To match on anything other than a path, define a [named matcher](#named-matchers) and refer to it using `@name`: To match on anything other than a path, define a [named matcher](#named-matchers) and refer to it using `@name`:
``` ```caddy-d
@post { @post {
method POST method POST
} }
@ -63,7 +63,7 @@ reverse_proxy @post localhost:9000
The wildcard matcher `*` matches all requests, and is only needed if a matcher token is required. For example, if the first argument you want to give a directive also happens to be a path, it would look exactly like a path matcher! So you can use a wildcard matcher to disambiguate, for example: The wildcard matcher `*` matches all requests, and is only needed if a matcher token is required. For example, if the first argument you want to give a directive also happens to be a path, it would look exactly like a path matcher! So you can use a wildcard matcher to disambiguate, for example:
``` ```caddy-d
root * /home/www/mysite root * /home/www/mysite
``` ```
@ -74,7 +74,7 @@ Otherwise, this matcher is not often used. It is convenient to omit it when poss
Because matching by path is so common, a single path matcher can be inlined, like so: Because matching by path is so common, a single path matcher can be inlined, like so:
``` ```caddy-d
redir /old.html /new.html redir /old.html /new.html
``` ```
@ -87,7 +87,7 @@ Path matcher tokens must start with a forward slash `/`.
Defining a matcher with a unique name gives you more flexibility, allowing you to combine [any available matchers](#standard-matchers) into a set: Defining a matcher with a unique name gives you more flexibility, allowing you to combine [any available matchers](#standard-matchers) into a set:
``` ```caddy-d
@name { @name {
... ...
} }
@ -97,7 +97,7 @@ Then you can use the matcher like so: `@name`
For example: For example:
``` ```caddy-d
@websockets { @websockets {
header Connection *Upgrade* header Connection *Upgrade*
header Upgrade websocket header Upgrade websocket
@ -140,7 +140,7 @@ Full matcher documentation can be found [in each respective matcher module's doc
⚠️ _This module is still experimental and, as such, may experience breaking changes._ ⚠️ _This module is still experimental and, as such, may experience breaking changes._
``` ```caddy-d
expression <cel...> expression <cel...>
``` ```
@ -150,14 +150,14 @@ As a special case, Caddy [placeholders](/docs/conventions#placeholders) (or [Cad
Examples: Examples:
``` ```caddy-d
expression {method}.startsWith("P") expression {method}.startsWith("P")
``` ```
### file ### file
``` ```caddy-d
file { file {
root <paths> root <paths>
try_files <files...> try_files <files...>
@ -182,7 +182,7 @@ An empty `file` matcher will see if the requested file (verbatim from the URI, r
### header ### header
``` ```caddy-d
header <field> <value> header <field> <value>
``` ```
@ -198,7 +198,7 @@ By request header fields.
### header_regexp ### header_regexp
``` ```caddy-d
header_regexp [<name>] <field> <regexp> header_regexp [<name>] <field> <regexp>
``` ```
@ -207,7 +207,7 @@ Like `header`, but supports regular expressions. Capture groups can be accessed
### host ### host
``` ```caddy-d
host <hosts...> host <hosts...>
``` ```
@ -216,7 +216,7 @@ Matches request by the `Host` header field of the request. It is not common to u
### method ### method
``` ```caddy-d
method <verbs...> method <verbs...>
``` ```
@ -225,13 +225,13 @@ By the method (verb) of the HTTP request. Verbs should be uppercase, like `POST`
### not ### not
``` ```caddy-d
not <any other matcher> not <any other matcher>
``` ```
or, to negate multiple matchers which get AND'ed, open a block: or, to negate multiple matchers which get AND'ed, open a block:
``` ```caddy-d
not { not {
<any other matchers...> <any other matchers...>
} }
@ -242,7 +242,7 @@ The results of the enclosed matchers will be negated.
### path ### path
``` ```caddy-d
path <paths...> path <paths...>
``` ```
@ -256,7 +256,7 @@ By request path, meaning the path component of the request's URI. Path matches a
### path_regexp ### path_regexp
``` ```caddy-d
path_regexp [<name>] <regexp> path_regexp [<name>] <regexp>
``` ```
@ -265,7 +265,7 @@ Like `path`, but supports regular expressions. Capture groups can be accessed vi
### protocol ### protocol
``` ```caddy-d
protocol http|https|grpc protocol http|https|grpc
``` ```
@ -274,7 +274,7 @@ By request protocol.
### query ### query
``` ```caddy-d
query <key>=<val>... query <key>=<val>...
``` ```
@ -283,7 +283,7 @@ By query string parameters. Should be a sequence of `key=value` pairs. Keys are
### remote_ip ### remote_ip
``` ```caddy-d
remote_ip <ranges...> remote_ip <ranges...>
``` ```

View file

@ -8,7 +8,7 @@ The Caddyfile has a way for you to specify options that apply globally. Some opt
The very top of your Caddyfile can be a **global options block**. This is a block that has no keys: The very top of your Caddyfile can be a **global options block**. This is a block that has no keys:
``` ```caddy
{ {
... ...
} }
@ -18,7 +18,7 @@ There can only be one at most, and it must be the first block of the Caddyfile.
Possible options are: Possible options are:
``` ```caddy
{ {
debug debug
http_port <port> http_port <port>

View file

@ -93,7 +93,7 @@ Adapts a configuration to Caddy's native JSON config structure and writes the ou
Note that a config which is successfully adapted may still fail validation. For an example of this, use this Caddyfile: Note that a config which is successfully adapted may still fail validation. For an example of this, use this Caddyfile:
``` ```caddy
localhost localhost
tls cert_notexist.pem key_notexist.pem tls cert_notexist.pem key_notexist.pem

View file

@ -112,7 +112,7 @@ That was _kind of a lot of work_ just for Hello World.
Another way to configure Caddy is with the [**Caddyfile**](/docs/caddyfile). The same config we wrote in JSON above can be expressed simply as: Another way to configure Caddy is with the [**Caddyfile**](/docs/caddyfile). The same config we wrote in JSON above can be expressed simply as:
``` ```caddy
:2015 :2015
respond "Hello, world!" respond "Hello, world!"

View file

@ -8,7 +8,7 @@ Create a new text file named `Caddyfile` (no extension).
The first thing to type in a Caddyfile is your site's address: The first thing to type in a Caddyfile is your site's address:
``` ```caddy
localhost localhost
``` ```
@ -18,7 +18,7 @@ localhost
Then hit enter and type what you want it to do, so it looks like this: Then hit enter and type what you want it to do, so it looks like this:
``` ```caddy
localhost localhost
respond "Hello, world!" respond "Hello, world!"
@ -43,7 +43,7 @@ Hello, world!</code></pre>
You can define multiple sites in a Caddyfile by wrapping them in curly braces `{ }`. Change your Caddyfile to be: You can define multiple sites in a Caddyfile by wrapping them in curly braces `{ }`. Change your Caddyfile to be:
``` ```caddy
localhost { localhost {
respond "Hello, world!" respond "Hello, world!"
} }

View file

@ -40,7 +40,7 @@ This is the most common way to get HTTPS.
Create a file called `Caddyfile` (no extension) where the first line is your domain name, for example: Create a file called `Caddyfile` (no extension) where the first line is your domain name, for example:
``` ```caddy
example.com example.com
respond "Hello, privacy!" respond "Hello, privacy!"

View file

@ -36,7 +36,7 @@ Then make a request to [localhost](https://localhost) (or whatever address you s
In the current working directory, create a file called `Caddyfile` with these contents: In the current working directory, create a file called `Caddyfile` with these contents:
``` ```caddy
localhost localhost
reverse_proxy 127.0.0.1:9000 reverse_proxy 127.0.0.1:9000
@ -50,7 +50,7 @@ You can then make a request to [https://localhost](https://localhost) to see it
It's easy to change the proxy's address: It's easy to change the proxy's address:
``` ```caddy
:2016 :2016
reverse_proxy 127.0.0.1:9000 reverse_proxy 127.0.0.1:9000

View file

@ -41,7 +41,7 @@ You can use another folder as the site root:
In the root of your site, create a file called `Caddyfile` with these contents: In the root of your site, create a file called `Caddyfile` with these contents:
``` ```caddy
localhost localhost
file_server file_server
@ -59,7 +59,7 @@ The [`file_server` directive](/docs/caddyfile/directives/file_server) has more o
If you don't have an index file but you want to display a file listing, use the `browse` argument: If you don't have an index file but you want to display a file listing, use the `browse` argument:
``` ```caddy
localhost localhost
file_server browse file_server browse
@ -67,7 +67,7 @@ file_server browse
You can also use another folder as the site root: You can also use another folder as the site root:
``` ```caddy
localhost localhost
root * /home/me/mysite root * /home/me/mysite

View file

@ -126,7 +126,7 @@ basicauth /secret/ Bob hiccup
``` ```
- **v2:** - **v2:**
``` ```caddy-d
basicauth /secret/* { basicauth /secret/* {
Bob JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX Bob JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX
} }
@ -137,8 +137,14 @@ basicauth /secret/* {
File browsing is now enabled through the [`file_server`](/docs/caddyfile/directives/file_server) directive. File browsing is now enabled through the [`file_server`](/docs/caddyfile/directives/file_server) directive.
- **v1:** `browse /subfolder/` - **v1:**
- **v2:** `file_server /subfolder/* browse` ```
browse /subfolder/
```
- **v2:**
```caddy-d
file_server /subfolder/* browse
```
### ext ### ext
@ -153,8 +159,14 @@ Implied file extensions can be done with [`try_files`](/docs/caddyfile/directive
Assuming you're serving PHP, the v2 equivalent is [`php_fastcgi`](/docs/caddyfile/directives/php_fastcgi). Assuming you're serving PHP, the v2 equivalent is [`php_fastcgi`](/docs/caddyfile/directives/php_fastcgi).
- **v1:** `fastcgi / localhost:9005 php` - **v1:**
- **v2:** `php_fastcgi localhost:9005` ```
fastcgi / localhost:9005 php
```
- **v2:**
```caddy-d
php_fastcgi localhost:9005
```
Note that the `fastcgi` directive from v1 did a lot under the hood, including trying files on disk, rewriting requests, and even redirecting. The v2 `php_fastcgi` directive also does these things for you, but the docs give its [expanded form](/docs/caddyfile/directives/php_fastcgi#expanded-form) that you can modify if your requirements are different. Note that the `fastcgi` directive from v1 did a lot under the hood, including trying files on disk, rewriting requests, and even redirecting. The v2 `php_fastcgi` directive also does these things for you, but the docs give its [expanded form](/docs/caddyfile/directives/php_fastcgi#expanded-form) that you can modify if your requirements are different.
@ -167,8 +179,14 @@ The subdirectives are different in v2 -- you probably will not need any for PHP.
A single directive [`encode`](/docs/caddyfile/directives/encode) is now used for all response encodings, including multiple compression formats. A single directive [`encode`](/docs/caddyfile/directives/encode) is now used for all response encodings, including multiple compression formats.
- **v1:** `gzip` - **v1:**
- **v2:** `encode gzip` ```
gzip
```
- **v2:**
```caddy-d
encode gzip
```
Fun fact: Caddy 2 also supports `zstd` (but no browsers do yet). Fun fact: Caddy 2 also supports `zstd` (but no browsers do yet).
@ -177,8 +195,14 @@ Fun fact: Caddy 2 also supports `zstd` (but no browsers do yet).
[Mostly unchanged](/docs/caddyfile/directives/header), but now way more powerful since it can do substring replacements in v2. [Mostly unchanged](/docs/caddyfile/directives/header), but now way more powerful since it can do substring replacements in v2.
- **v1:** `header / Strict-Transport-Security max-age=31536000;` - **v1:**
- **v2:** `header Strict-Transport-Security max-age=31536000;` ```
header / Strict-Transport-Security max-age=31536000;
```
- **v2:**
```caddy-d
header Strict-Transport-Security max-age=31536000;
```
### log ### log
@ -187,7 +211,7 @@ Enables access logging; the [`log`](/docs/caddyfile/directives/log) directive ca
The recommended way to enable access logging is simply: The recommended way to enable access logging is simply:
``` ```caddy-d
log log
``` ```
@ -201,7 +225,7 @@ log access.log
``` ```
- **v2:** - **v2:**
``` ```caddy-d
log { log {
output file access.log output file access.log
format single_field common_log format single_field common_log
@ -223,8 +247,14 @@ Websocket proxying "just works" in v2; there is no need to "enable" websockets l
The `without` subdirective has been removed because [rewrite hacks](#rewrite) are no longer necessary in v2 thanks to improved matcher support. The `without` subdirective has been removed because [rewrite hacks](#rewrite) are no longer necessary in v2 thanks to improved matcher support.
- **v1:** `proxy / localhost:9005` - **v1:**
- **v2:** `reverse_proxy localhost:9005` ```
proxy / localhost:9005
```
- **v2:**
```caddy-d
reverse_proxy localhost:9005
```
### redir ### redir
@ -249,7 +279,7 @@ rewrite {
} }
``` ```
- **v2:** - **v2:**
``` ```caddy-d
@mobile { @mobile {
header User-Agent *mobile* header User-Agent *mobile*
} }
@ -277,8 +307,14 @@ Because it accepts a matcher in v2, this means you can also change the site root
The v2 equivalent is [`respond`](/docs/caddyfile/directives/respond), which can also write a response body. The v2 equivalent is [`respond`](/docs/caddyfile/directives/respond), which can also write a response body.
- **v1:** `status 404 /secrets/` - **v1:**
- **v2:** `respond /secrets/* 404` ```
status 404 /secrets/
```
- **v2:**
```caddy-d
respond /secrets/* 404
```
### templates ### templates