globalopts: Add servers name (#292)

Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
Daniel Santos 2023-02-08 00:22:25 -07:00 committed by GitHub
parent 0956f710c1
commit 24d9769d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,6 +96,7 @@ Possible options are:
# Server Options
servers [<listener_address>] {
name <name>
listener_wrappers {
<listener_wrappers...>
}
@ -360,6 +361,38 @@ For example, to configure different options for the servers on ports `:80` and `
}
```
##### `name`
A custom name to assign to this server. Usually helpful to identify a server by its name in logs and metrics. If not set, Caddy will define it dynamically using a `srvX` pattern, where `X` starts with 0 and increments based on the number of servers in the config.
<aside class="tip">
Keep in mind there's a caveat if you want to name your HTTP server and are using Auto-HTTPS. The server name config doesn't persist past adapting the config, and Auto-HTTPS happens at runtime, from the JSON config.
To overcome this, you'll need to create an empty `:80` or `http://` site block and set this option. With that Auto-HTTPS will add its redirect routes to that server.
</aside>
For example:
```caddy
{
servers :443 {
name https
}
servers :80 {
name http
}
}
example.com {
}
http:// {
}
```
##### `listener_wrappers`
Allows configuring [listener wrappers](/docs/json/apps/http/servers/listener_wrappers/), which can modify the behaviour of the socket listener. They are applied in the given order.