Explaining sample file

Matt Holt 2015-01-19 16:26:54 -07:00
parent 62ebeca934
commit 700e15fcf7

@ -15,13 +15,13 @@ The Caddyfile is very easy to use. It can configure either one or multiple serve
The first line is always an address to listen on: The first line is always an address to listen on:
``` ```
yourdomain.com:80 mydomain.com:80
``` ```
The rest of the file consists of lines with directives and parameters (arguments), for example: The rest of the file consists of lines with directives and parameters (arguments), for example:
``` ```
yourdomain.com:80 mydomain.com:80
gzip gzip
ext .html ext .html
@ -30,19 +30,23 @@ ext .html
To configure multiple servers (virtual hosts) in the same Caddyfile, wrap the directives pertaining for each server in a curly brace block, for example: To configure multiple servers (virtual hosts) in the same Caddyfile, wrap the directives pertaining for each server in a curly brace block, for example:
``` ```
yourdomain.com:80 { mydomain.com:80 {
redir / :443 301 redirect / :443 301
} }
# Curly braces can be on their own line if you prefer # Curly braces can be on their own line if you prefer
yourdomain.com:443 mydomain.com:443
{ {
gzip gzip
ext .html ext .html .htm
tls cert.pem key.pem tls cert.pem key.pem
} }
``` ```
Notice that a `#` token turns the rest of the line into a comment. Notice that a `#` token turns the rest of the line into a comment.
In the above file, the keywords `redir`, `gzip`, `ext`, and `tls` are directives. There are others. Each directive is bound to a unique piece of middleware that wraps every request in order to satisfy the Caddyfile. In the above file, the keywords `redirect`, `gzip`, `ext`, and `tls` are directives. There are others. Each directive is bound to a unique piece of middleware that wraps every request in order to satisfy the Caddyfile.
To learn about what directives are available, please see the list of directives in this wiki.
For those who want to check their understanding: the file above serves `yourdomain.com` on ports 80 and 443 (the HTTP and HTTPS ports). All requests to port 80 are redirected to 443, the secure port, with a 301 status code. All requests to port 443 are gzipped. Then, if an extension was not added to the URL, the .html extension will be internally added if the resource exists (and if not, it tries .htm). In other words, it serves clean, extensionless URLs by inferring the file extension. The tls line enables TLS using the certificate and key files listed.