docs: Some random polish

Just a bunch of little things that I think would help users from frequently asked forum questions.
This commit is contained in:
Francis Lavoie 2022-06-05 14:32:04 -04:00
parent 8f61c3c71f
commit 71fdb1716e
No known key found for this signature in database
GPG key ID: E73DB3ECE64E7885
5 changed files with 40 additions and 23 deletions

View file

@ -24,9 +24,9 @@ The Caddyfile's structure can be described visually:
Key points:
- An optional **global options block** can be the very first thing in the file.
- Otherwise, the first line of the Caddyfile is **always** the address(es) of the site to serve.
- All directives and matchers **must** go in a site block. There is no global scope or inheritence across site blocks.
- An optional [**global options block**](#global-options) can be the very first thing in the file.
- Otherwise, the first line of the Caddyfile is **always** the [address(es)](#addresses) of the site to serve.
- All [directives](#directives) and [matchers](#matchers) **must** go in a site block. There is no global scope or inheritence across site blocks.
- If there is **only one site block**, its curly braces `{ }` are optional.
A Caddyfile consists of at least one or more site blocks, which always starts with one or more [addresses](#addresses) for the site. Any directives appearing before the address will be confusing to the parser.
@ -145,7 +145,7 @@ Inside quoted tokens, all other characters are treated literally, including spac
```caddy-d
directive "first line
second line"
second line"
```
You can also use a backtick <code>`</code> to quote tokens; these are convenient when tokens themselves contain double quotes, e.g. JSON text:
@ -308,7 +308,8 @@ Comments start with `#` and proceed until the end of the line:
directive # or go at the end
```
The hash character `#` cannot appear in the middle of a token (i.e. it must be preceded by a space or appear at the beginning of a line). This allows the use of hashes within URIs or other values without requiring quoting.
The hash character `#` for a comment cannot appear in the middle of a token (i.e. it must be preceded by a space or appear at the beginning of a line). This allows the use of hashes within URIs or other values without requiring quoting.
## Environment variables
@ -319,7 +320,7 @@ If your configuration relies on environment variables, you can use them in the C
{$SITE_ADDRESS}
```
Environment variables in this form are substituted before parsing begins, so they can expand to empty values, partial tokens, complete tokens, or even multiple tokens and lines.
Environment variables in this form are substituted before Caddyfile parsing begins, so they can expand to empty values, partial tokens, complete tokens, or even multiple tokens and lines.
A default value can be specified for when the environment variable is not found, by using `:` as the delimiter between the variable name and the default value:
@ -327,7 +328,8 @@ A default value can be specified for when the environment variable is not found,
{$DOMAIN:localhost}
```
If you want to defer the substitution of an environment variable until runtime, you can use the [standard `{env.*}` placeholders](/docs/conventions#placeholders).
If you want to defer the substitution of an environment variable until runtime, you can use the [standard `{env.*}` placeholders](/docs/conventions#placeholders). Note that not all parts of the config support these placeholders though, since a line of code is necessary to perform the replacement; placeholder replacement is not automatic and needs to be performed at runtime. If it doesn't seem to work, please file an issue to request support for it.
## Global options

View file

@ -213,13 +213,13 @@ Load balancing is used whenever more than one upstream is defined.
- `random_choose <n>` - selects two or more upstreams randomly, then chooses one with least load (`n` is usually 2)
- `first` - choose first available upstream, from the order they are defined in the config
- `round_robin` - iterate each upstream in turn
- `least_conn` - choose upstream with fewest number of current requests
- `ip_hash` - map client IP to sticky upstream
- `uri_hash` - map URI to sticky upstream
- `header [field]` - map request header to sticky upstream. If the specified header is not present, a random upstream is selected.
- `cookie [<name> [<secret>]]` - based on the given cookie (default name is `lb` if not specified), which value is hashed; optionally with a secret for HMAC-SHA256
- `least_conn` - choose upstream with fewest number of current requests; if more than one host has the least number of requests, then one of the hosts is chosen at random
- `ip_hash` - map the client IP to sticky upstream
- `uri_hash` - map the request URI (path and query) to sticky upstream
- `header [field]` - map request header to sticky upstream; if the specified header is not present, a random upstream is selected
- `cookie [<name> [<secret>]]` - based on the given cookie (default name is `lb` if not specified), the cookie value is hashed, optionally with a secret for HMAC-SHA256; on the first request from a client, a random upstream is selected
- **lb_try_duration** <span id="lb_try_duration"/> is a [duration value](/docs/conventions#durations) that defines how long to try selecting available backends for each request if the next available host is down. By default, this retry is disabled. Clients will wait for up to this long while the load balancer tries to find an available upstream host.
- **lb_try_duration** <span id="lb_try_duration"/> is a [duration value](/docs/conventions#durations) that defines how long to try selecting available backends for each request if the next available host is down. By default, this retry is disabled. Clients will wait for up to this long while the load balancer tries to find an available upstream host. A reasonable starting point might be `5s`, since the HTTP transport's default dial timeout is `3s`, so that should allow for at least one retry; but feel free to experiment to find the right balance for your usecase.
- **lb_try_interval** <span id="lb_try_interval"/> is a [duration value](/docs/conventions#durations) that defines how long to wait between selecting the next host from the pool. Default is `250ms`. Only relevant when a request to an upstream host fails. Be aware that setting this to 0 with a non-zero `lb_try_duration` can cause the CPU to spin if all backends are down and latency is very low.
@ -242,8 +242,8 @@ Active health checks perform health checking in the background on a timer:
Passive health checks happen inline with actual proxied requests:
- **fail_duration** <span id="fail_duration"/> is a [duration value](/docs/conventions#durations) that defines how long to remember a failed request. A duration > 0 enables passive health checking.
- **max_fails** <span id="max_fails"/> is the maximum number of failed requests within `fail_duration` that are needed before considering a backend to be down; must be >= 1; default is 1.
- **fail_duration** <span id="fail_duration"/> is a [duration value](/docs/conventions#durations) that defines how long to remember a failed request. A duration > `0` enables passive health checking; it's off by default. A reasonable starting point might be `30s`, to balance error rates with responsiveness when bringing an unhealthy upstream back online; but feel free to experiment to find the right balance for your usecase.
- **max_fails** <span id="max_fails"/> is the maximum number of failed requests within `fail_duration` that are needed before considering a backend to be down; must be >= `1`; default is `1`.
- **unhealthy_status** <span id="unhealthy_status"/> counts a request as failed if the response comes back with one of these status codes. Can be a 3-digit status code or a status code class ending in `xx`, for example: `404` or `5xx`.
- **unhealthy_latency** <span id="unhealthy_latency"/> is a [duration value](/docs/conventions#durations) that counts a request as failed if it takes this long to get a response.
- **unhealthy_request_count** <span id="unhealthy_request_count"/> is the permissible number of simultaneous requests to a backend before marking it as down.

View file

@ -14,10 +14,15 @@ $(function() {
let url = '#' + item.innerText.replace(/_/g, "-");
$(item).html('<a href="' + url + '" style="color: inherit;" title="' + text + '">' + text + '</a>');
});
$('pre.chroma .k:contains("servers")')
// Add links on comments to their respective sections
$('pre.chroma .c1')
.filter((k, item) => item.innerText.includes('#'))
.map(function(k, item) {
let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;');
$(item).html('<a href="#server-options" style="color: inherit;" title="Server Options">' + text + '</a>');
let text = item.innerText;
let before = text.slice(0, text.indexOf('#'));
text = text.slice(text.indexOf('#'));
let url = '#' + text.replace(/#/g, '').trim().toLowerCase().replace(/ /g, "-");
$(item).html(before + '<a href="' + url + '" style="color: inherit;" title="' + text + '">' + text + '</a>');
});
});
</script>
@ -258,7 +263,7 @@ Configures the ACME DNS challenge provider to use for all ACME transactions. The
##### `on_demand_tls`
Configures [On-Demand TLS](/docs/automatic-https#on-demand-tls) where it is enabled, but does not enable it (to enable it, use the [on_demand `tls` subdirective](/docs/caddyfile/directives/tls#syntax)). Highly recommended if using in production environments, to prevent abuse.
- **ask** will cause Caddy to make an HTTP request to the given URL with a query string of `?domain=` containing the value of the domain name. If the endpoint returns 200 OK, Caddy will be authorized to obtain a certificate for that name.
- **ask** will cause Caddy to make an HTTP request to the given URL with a query string of `?domain=` containing the value of the domain name. If the endpoint returns a `2xx` status code, Caddy will be authorized to obtain a certificate for that name. Any other status code will result in cancelling issuance of the certificate.
- **interval** and **burst** allows `<n>` certificate operations within `<duration>` interval.

View file

@ -96,7 +96,7 @@ example.com {
```
To remove it for **multiple domains** at once:
To remove it for **multiple domains** at once; this uses the `{labels.*}` placeholders which are the parts of the hostname, 0-indexed from the right (e.g. 0=com, 1=example-one, 2=www):
```caddy
www.example-one.com, www.example-two.com {
@ -180,11 +180,12 @@ When a web page does its own routing, servers may receive lots of requests for p
The main idea is to have the server "try files" to see if the requested file exists server-side, and if not, fall back to an index file where the client does the routing (usually with client-side JavaScript): `try_files {path} /index.html`
The most basic SPA config usually looks something like this:
A typical SPA config usually looks something like this:
```caddy
example.com {
root * /path/to/site
encode gzip
try_files {path} /index.html
file_server
}
@ -194,6 +195,8 @@ If your SPA is coupled with an API or other server-side-only endpoints, you will
```caddy
example.com {
encode gzip
handle /api/* {
reverse_proxy backend:8000
}

View file

@ -15,7 +15,14 @@ When specifying a network address to dial or bind, Caddy accepts a string in the
network/address
```
The network part is optional, and is anything that [Go's `net` package](https://golang.org/pkg/net/) recognizes. The default network is `tcp`. If a network is specified, a single forward slash `/` must separate the network and address portions.
The network part is optional (defaulting to `tcp`), and is anything that [Go's `net.Dial` function](https://pkg.go.dev/net#Dial) recognizes. If a network is specified, a single forward slash `/` must separate the network and address portions.
The network can be any of the following; ones suffixed with `4` or `6` are IPv4 or IPv6 only, respectively:
- TCP: `tcp`, `tcp4`, `tcp6`
- UDP: `udp`, `udp4`, `udp6`
- IP: `ip`, `ip4`, `ip6`
- Unix: `unix`, `unixgram`, `unixpacket`
The address part may be any of these forms:
@ -28,7 +35,7 @@ The host may be any hostname, resolvable domain name, or IP address.
The port may be a single value (`:8080`) or an inclusive range (`:8080-8085`). A port range will be multiplied into singular addresses. Not all config fields accept port ranges. The special port `:0` means any available port.
A unix socket path is only acceptable when using a unix* network type. The forward slash that separates the network and address is not considered part of the path.
A unix socket path is only acceptable when using a `unix*` network type. The forward slash that separates the network and address is not considered part of the path.
Valid examples: