Module ID
http.servers.<name>
Each server is defined by a unique name in the configuration.
Server Configuration
Listen Addresses
Socket addresses to bind listeners to. Accepts network addresses that may include port ranges. Listener addresses must be unique across all defined servers.
Protocol Settings
Specifies which HTTP protocols to enable. Supported values:HTTP/2 operates only over TLS (HTTPS). HTTP/3 opens a UDP socket to serve QUIC connections.
h1- HTTP/1.1h2- HTTP/2 over TLSh2c- Cleartext HTTP/2h3- HTTP/3 over QUIC
If enabling
h2 or h2c, h1 must also be enabled due to Go standard library limitations.Overrides
protocols for each parallel address in listen. A nil value or element indicates that protocols will be used instead.Timeouts
How long to allow a read from a client’s upload. Setting this to a short, non-zero value can mitigate slowloris attacks, but may affect legitimately slow clients.
Like
read_timeout but specifically for request headers.How long to allow a write to a client. Setting this to a small value when serving large files may negatively affect legitimately slow clients.
Maximum time to wait for the next request when keep-alives are enabled. If zero, a default timeout of 5m is applied to help avoid resource exhaustion.
TCP Keep-Alive
Interval at which TCP keepalive packets are sent to keep the connection alive at the TCP layer when no other data is being transmitted. If negative, keepalive packets are not sent.
Time that the connection must be idle before the first TCP keep-alive probe is sent when no other data is being transmitted. If negative, underlying socket value is unchanged.
Maximum number of TCP keep-alive probes that should be sent before dropping a connection. If negative, underlying socket value is unchanged.
Request Limits
Maximum size to parse from a client’s HTTP request headers.
Enable full-duplex communication for HTTP/1 requests. Only has an effect if Caddy was built with Go 1.21 or later.
This is an EXPERIMENTAL feature and subject to change. Test thoroughly with your HTTP clients, as some older clients may not support full-duplex HTTP/1 which can cause them to deadlock.
Routes and Handlers
Describes how this server will handle requests. Routes are executed sequentially. Each route’s matchers are evaluated first, then its grouping. If it matches and has not been mutually-excluded by its grouping, its handlers are executed sequentially.By default, all unrouted requests receive a 200 OK response to indicate the server is working.
Mapping of reusable routes that can be invoked by their name. This optimizes memory usage when the same route is needed for many subroutes, by having handlers and matchers provisioned once but used from many places.
EXPERIMENTAL: Subject to change or removal.
How this server will handle errors returned from any of the handlers in the primary routes. If the primary handler chain returns an error, the error along with its recommended status code are bubbled back to the HTTP server which executes a separate error route.
TLS Configuration
How to handle TLS connections. At least one policy is required to enable HTTPS on this server if automatic HTTPS is disabled or does not apply.
Configures or disables automatic HTTPS within this server. HTTPS is enabled automatically and by default when qualifying names are present in a Host matcher and/or when the server is listening only on the HTTPS port.
If true, requires that a request’s Host header match the value of the ServerName sent by the client’s TLS ClientHello. Often a necessary safeguard when using TLS client authentication.
Trusted Proxies
A module which provides a source of IP ranges from which requests should be trusted. By default, no proxies are trusted.This can be used as a default set of ranges for handlers or matchers in routes to pick up, instead of needing to configure each of them. For example, the
reverse_proxy handler uses this to trust sensitive incoming X-Forwarded-* headers.Module namespace: http.ip_sourcesHeaders from which the client IP address could be read from. These will be considered in order, with the first good value being used as the client IP.This depends on
trusted_proxies being configured and the request being validated as coming from a trusted proxy.If greater than zero, enables strict ClientIPHeaders parsing. The headers will be parsed from right to left, and the first value that is both valid and doesn’t match the trusted proxy list will be used as client IP.If zero, the headers will be parsed from left to right, and the first value that is a valid IP address will be used.
If true, enables trusting socket connections (e.g. Unix domain sockets) as coming from a trusted proxy.
Logging
Enables access logging and configures how access logs are handled in this server. To minimally enable access logs, simply set this to a non-null, empty struct.
Advanced Settings
List of listener wrapper modules, which can modify the behavior of the base listener. They are applied in the given order.Module namespace:
caddy.listenersList of packet conn wrapper modules, which can modify the behavior of the base packet conn. They are applied in the given order.Module namespace:
caddy.packetconnsIf set, overrides whether QUIC listeners allow 0-RTT (early data). If nil, the default behavior is used (currently allowed).
One reason to disable 0-RTT is if a remote IP matcher is used, which introduces a dependency on the remote address being verified if routing happens before the TLS handshake completes.
Configuration Example
Context Values
The server sets the following context values on requests:ServerCtxKey- Reference to the server instanceVarsCtxKey- Request’s variable tableOriginalRequestCtxKey- Partial copy of the unmodified request
Methods
ServeHTTP
The entry point for all HTTP requests. This method:- Enables full-duplex for HTTP/1 if configured
- Sets the Server header
- Advertises HTTP/3 if enabled
- Prepares the request with a replacer and context
- Handles ACME HTTP challenges
- Executes the primary handler chain
- Invokes error handler chain if needed
PrepareRequest
Fills the request for use in a Caddy HTTP handler chain. Sets up:- Replacer context
- Server reference
- Trusted proxy detection
- Client IP determination
- Request variables
- Original request copy
The server enforces strict host matching when
strict_sni_host is enabled, ensuring the TLS ServerName matches the Host header.