From ad4db1128805d9674c9057a812c16394a69ca35b Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Mon, 19 Jan 2015 16:44:48 -0700 Subject: [PATCH] Explaining some available directives --- Caddyfile-Directives.md | 105 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Caddyfile-Directives.md diff --git a/Caddyfile-Directives.md b/Caddyfile-Directives.md new file mode 100644 index 0000000..013c2c0 --- /dev/null +++ b/Caddyfile-Directives.md @@ -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 +``` \ No newline at end of file