Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs for PR caddyserver/caddy#6573 #424

Open
wants to merge 17 commits into
base: 2.9
Choose a base branch
from
38 changes: 37 additions & 1 deletion src/docs/markdown/caddyfile/directives/bind.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ Note that binding sites inconsistently may result in unintended consequences. Fo
## Syntax

```caddy-d
bind <hosts...>
bind <hosts...> {
protocols <protocols...>
}
```

- **&lt;hosts...&gt;** is the list of host interfaces to bind which to bind the listener.
- **&lt;protocols...&gt;** is an optional override of the HTTP protocols to enable for the listener, see the [server options](/docs/caddyfile/options#protocols) for its accepted values and their meanings.


## Examples
Expand Down Expand Up @@ -64,6 +67,39 @@ example.com {
}
```

To bind to a Unix domain socket at `/run/caddy/stream.sock` that serves h1 and h2, and another at `/run/caddy/dgram.sock` that serves h3:

```caddy
example.com {
bind unix//run/caddy/stream.sock {
protocols h1 h2
}
bind unixgram//run/caddy/dgram.sock {
protocols h3
}
}
```

To bind to inherited file descriptors specified with [environment placeholders](/docs/conventions#placeholders):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should explain a bit why you'd want to use file descriptors. As a reader, I think "but why?"


```caddy
http://example.com {
bind fd/{env.CADDY_HTTP_FD} {
protocols h1
}
redir https://example.com{uri} permanent
}

https://example.com {
bind fd/{env.CADDY_HTTPS_FD} {
protocols h1 h2
}
bind fdgram/{env.CADDY_HTTP3_FD} {
protocols h3
}
}
```

To bind one domain to two different interfaces, with different responses:

```caddy
Expand Down
29 changes: 27 additions & 2 deletions src/docs/markdown/caddyfile/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Possible options are (click on each option to jump to its documentation):
debug
http_port <port>
https_port <port>
default_bind <hosts...>
default_bind <hosts...> {
protocols <protocols...>
}
order <dir1> first|last|[before|after <dir2>]
storage <module_name> {
<options...>
Expand Down Expand Up @@ -192,21 +194,44 @@ Default: `443`


##### `default_bind`
The default bind address(es) to be used for all sites, if the [`bind` directive](/docs/caddyfile/directives/bind) is not used in the site. Default: empty, which binds to all interfaces.
The default bind address(es) and optional HTTP protocol(s) (`h1|h2|h2c|h3`) to serve with them for all sites, if the [`bind` directive](/docs/caddyfile/directives/bind) is not used in the site. If multiple `default_bind` directives are present, each will be applied to servers with no `bind` directive in the order they were given. Default: empty, which binds to all interfaces, and serves the default protocols (`h1 h2 h3`) on them.

<aside class="tip">

Keep in mind that this will only apply to servers which are generated by the Caddyfile; this means that the HTTP server created by [Automatic HTTPS](/docs/automatic-https) for HTTP-to-HTTPS redirects will not inherit these bind addresses. To work around this, make sure to declare an `http://` site (it can be empty, with no directives) so that it exists when the Caddyfile is adapted, to receive the bind addresses.

</aside>

For example, to bind to `10.0.0.1` when no other address(es) are specified:

```caddy
{
default_bind 10.0.0.1
}
```

To disable HTTP/3 unless otherwise specified:

```caddy
{
default_bind {
protocols h1 h2
}
}
```

To create default listeners from file descriptors `3` and `4`:

```caddy
{
default_bind fd/3 {
protocols h1 h2
}
default_bind fdgram/4 {
protocols h3
}
}
```

##### `order`
Assigns an order to HTTP handler directive(s). As HTTP handlers execute in a sequential chain, it is necessary for the handlers to be executed in the right order. Standard directives have [a pre-defined order](/docs/caddyfile/directives#directive-order), but if using third-party HTTP handler modules, you'll need to define the order explicitly by either using this option or placing the directive in a [`route` block](/docs/caddyfile/directives/route). Ordering can be described absolutely (`first` or `last`), or relatively (`before` or `after`) to another directive.
Expand Down
5 changes: 4 additions & 1 deletion src/docs/markdown/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The network can be any of the following; ones suffixed with `4` or `6` are IPv4
- UDP: `udp`, `udp4`, `udp6`
- IP: `ip`, `ip4`, `ip6`
- Unix: `unix`, `unixgram`, `unixpacket`
- File descriptors: `fd`, `fdgram`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a short paragraph to explain what a "file descriptor" means in this context would help


The address part may be any of these forms:

Expand All @@ -42,10 +43,12 @@ The address part may be any of these forms:
- `/path/to/unix/socket`
- `/path/to/unix/socket|0200`

The host may be any hostname, resolvable domain name, or IP address.
The host may be any hostname, resolvable domain name, IP address, or file descriptor number.

In the case of IPv6 addresses, the address must be enclosed in square brackets `[]`. The zone identifier (starting with `%`) is optional (often used for link-local addresses).

In the case of file descriptors, the host must be an unsigned [integer literal](https://go.dev/ref/spec#Integer_literals).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we explain here a bit how this works? Like what does the number actually represent? I don't have a good understanding of how file descriptors are useful, and I assume most users wouldn't understand the point of it either.

In all these docs, I only see examples with {env.*} but no actual concrete values, so as a user I would have no idea what the env var values should even look like.


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.
Expand Down