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

Closed
wants to merge 17 commits into 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 <protocol> ...
Copy link
Member

Choose a reason for hiding this comment

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

Is it moreseo like this?

Suggested change
protocols <protocol> ...
protocols <protocols...>

<protocol> ... implies a single protocol is given, which can itself have additional options, but from my reading of the examples, it's just a list of protocols.

Copy link
Author

Choose a reason for hiding this comment

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

with the ... after, I thought this was the notation for at least one protocol, then possibly more. there are other options that use both, but I thought the distinction was >=1 vs >=0.

Copy link
Member

@francislavoie francislavoie Oct 10, 2024

Choose a reason for hiding this comment

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

We use <args...> to to mean "one or more". See https://caddyserver.com/docs/caddyfile/directives#syntax. If it was optional, it would be [<args...>].

}
```

- **&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.
Copy link
Member

Choose a reason for hiding this comment

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

This should probably list the allowed options



## 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 <protocol> ...
}
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) 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.
Copy link
Member

Choose a reason for hiding this comment

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

Prefer to show the options in the way they would appear in the Caddyfile

Suggested change
The default bind address(es) and optional HTTP protocol(s) 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.
The default bind address(es) and optional HTTP protocol(s) 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.

Also this section should probably mention the list of allowed options


<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:
MayCXC marked this conversation as resolved.
Show resolved Hide resolved

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

to create default listeners from file descriptors given by [environment placeholders](/docs/conventions#placeholders):
MayCXC marked this conversation as resolved.
Show resolved Hide resolved

```caddy
{
default_bind fd/{env.CADDY_HTTPS_FD} {
protocols h1 h2
}
default_bind fdgram/{env.CADDY_HTTP3_FD} {
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
3 changes: 2 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,7 +43,7 @@ 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).

Expand Down