mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-07 10:15:06 -04:00
Explaining some available directives
parent
700e15fcf7
commit
ad4db11288
105
Caddyfile-Directives.md
Normal file
105
Caddyfile-Directives.md
Normal file
@ -0,0 +1,105 @@
|
||||
This page describes the Caddyfile directives and how to use them. Each directive has a corresponding middleware which alters the behavior of the server.
|
||||
|
||||
This list is presented alphabetically. The order in which directives appear in the Caddyfile does not matter.
|
||||
|
||||
## List of directives
|
||||
|
||||
|
||||
#### ext
|
||||
|
||||
Internally adds extensions to the requests. Extensions will be tried in the order listed. This allows you to easily serve cleaner URLs.
|
||||
|
||||
```
|
||||
ext .html .html .txt
|
||||
```
|
||||
|
||||
|
||||
#### gzip
|
||||
|
||||
Enables gzip compression if the client supports it.
|
||||
|
||||
```
|
||||
gzip
|
||||
```
|
||||
|
||||
|
||||
#### header
|
||||
|
||||
Adds header(s) of the specified name and value to the responses of requests matching the request path. You can specify a single header and value on a line or group them under the same path with curly braces.
|
||||
|
||||
```
|
||||
header /one X-Some-Header 1
|
||||
header /multiple {
|
||||
Access-Control-Allow-Origin *
|
||||
Access-Control-Allow-Methods "POST, GET, OPTIONS"
|
||||
```
|
||||
|
||||
#### import
|
||||
|
||||
Import acts like "include" in other languages/syntaxes. It replaces that line with the contents of another file. Useful for reusing common settings.
|
||||
|
||||
```
|
||||
import shared.conf
|
||||
```
|
||||
|
||||
|
||||
#### log
|
||||
|
||||
Activates logging. Right now, only requests can be logged. You may optionally specify an output file and format.
|
||||
|
||||
```
|
||||
log requests /var/log/access.log "Got a request: {method} {path}"
|
||||
```
|
||||
|
||||
To specify a format but use the default filename, use `_` as the filename (Go-style). The filename can also be `stdout` or `stderr` instead of an actual file.
|
||||
|
||||
The following variables are available when specifying the format:
|
||||
|
||||
- {method}
|
||||
- {scheme}
|
||||
- {host}
|
||||
- {path}
|
||||
- {query}
|
||||
- {fragment}
|
||||
- {proto}
|
||||
- {remote}
|
||||
- {port}
|
||||
- {uri}
|
||||
- {when}
|
||||
- {status}
|
||||
- {size}
|
||||
|
||||
#### redirect
|
||||
|
||||
HTTP redirect with the given status code.
|
||||
|
||||
```
|
||||
redirect /from /to 302
|
||||
```
|
||||
|
||||
|
||||
#### rewrite
|
||||
|
||||
Internally rewrites a request from one path to another.
|
||||
|
||||
```
|
||||
rewrite /from /to
|
||||
```
|
||||
|
||||
|
||||
#### root
|
||||
|
||||
Specifies the root directory from which to serve files.
|
||||
|
||||
```
|
||||
root /usr/www
|
||||
```
|
||||
|
||||
|
||||
#### tls
|
||||
|
||||
Enables TLS (better than plain SSL) using the specified certificate and key files.
|
||||
|
||||
```
|
||||
tls cert.pem key.pem
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user