Join our Newsletter — 33% off our NHI Course
Home› Guides› Caddy Web Server Security Guide: Automatic HTTPS, Admin…
Guide Web & API Security

Caddy Web Server Security Guide: Automatic HTTPS, Admin API and Reverse Proxy Settings

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 19 November 2026 13 min read
On this page

Caddy is secure by default in the ways that usually go wrong first, such as obtaining and renewing TLS certificates, but a safe deployment still depends on locking down its admin API, trusting the right proxies, setting timeouts and keeping certificate keys and secrets out of reach. Caddy is popular with small teams and self-hosters because a few lines of Caddyfile give a working HTTPS site or reverse proxy. That simplicity hides several settings that deserve a deliberate decision, especially the admin endpoint that listens on localhost:2019 by default and can replace the whole running configuration.

This guide walks through those settings using Caddy's own documentation: the admin API, automatic HTTPS and its issuers, On-Demand TLS, reverse proxy header handling and upstream TLS, server timeouts and limits, logging and running Caddy as an unprivileged service. Recommendations that go beyond the documentation are labelled as NHI Mgmt Group guidance.

This is an independent guide from NHI Mgmt Group, based on Caddy's public documentation as of November 2026. It is not sponsored or reviewed by the Caddy project. Product features change, so confirm settings against Caddy's current documentation.

Key takeaways

  • The admin API listens on localhost:2019 unless changed, and can load a new configuration or stop the server. Bind it to a permissioned Unix socket, or turn it off with admin off if you do not need live changes.
  • Never expose the admin port publicly. Caddy's documentation warns that otherwise "anyone can control your server".
  • Automatic HTTPS obtains and renews certificates for named sites and redirects HTTP to HTTPS. Set an ACME account email and use the staging endpoint while testing.
  • On-Demand TLS must be restricted with an ask endpoint in production to prevent abuse.
  • Configure trusted_proxies only for the CIDR ranges of proxies or CDNs you actually sit behind, so client IP addresses in logs and rules cannot be spoofed.
  • Do not use tls_insecure_skip_verify to upstreams in production, and set read and write timeouts, which have no limit by default.

The admin API: Caddy's most sensitive interface

Caddy is configured through a REST admin API. According to the API documentation, the default address is localhost:2019; the CADDY_ADMIN environment variable can change it, and an address in the Caddy configuration takes precedence over both. Endpoints include:

  • POST /load, which sets or replaces the active configuration.
  • POST /stop, which shuts down the server and exits the process.
  • GET, POST, PUT, PATCH and DELETE on /config/[path], which read and modify configuration at a path.
  • GET /pki/ca/<id> and its certificates endpoint, which return details of Caddy's internal certificate authority.
  • GET /reverse_proxy/upstreams, which returns upstream status.

Anyone who can reach this endpoint can therefore rewrite routing, add a proxy to an address of their choice, or take the site offline. Binding to localhost limits exposure to the same machine, but on a shared host, in a container with other processes, or where any local application can be tricked into making HTTP requests, localhost is not a strong boundary. Server-side request forgery in an application behind Caddy is one route to reach it; see the SSRF Prevention Guide.

Caddy's documentation recommends protecting the admin endpoint by isolating processes, patching vulnerable programs, and configuring the endpoint to bind to a permissioned Unix socket. The global options documentation adds that the Caddy process user must be able to create the socket path itself; creating an empty file with touch first is not enough.

The admin global option controls the endpoint:

  • admin off disables it. Configuration changes then require a stop and start of the process.
  • For a loopback listener, the default allowed origins are localhost, ::1 and 127.0.0.1 with the listen port.
  • enforce_origin enforces the Origin header. The documentation says to use it only on a development machine when you need browser access to the admin API.
  • If you set a non-loopback address such as admin :2020, the documentation warns that the port "should not be exposed publicly, otherwise anyone can control your server".

NHI Mgmt Group recommends: use admin off on production hosts that are configured by file and reloaded by the service manager; where live configuration is needed, use a Unix socket readable only by the Caddy user and the deployment tool; and block port 2019 at the host firewall as a second layer.

Automatic HTTPS and certificate issuers

The automatic HTTPS documentation explains that Caddy activates it when it knows a domain name or IP address it serves, for example from a Caddyfile site address. It then obtains and renews certificates and redirects HTTP to HTTPS on port 80. Automatic HTTPS never overrides explicit configuration.

For public names, Caddy uses ACME certificate authorities: Let's Encrypt is tried first, with ZeroSSL as a fallback. Localhost, IP addresses and internal hostnames are served with certificates from Caddy's own local CA, which has a root and an intermediate. The root is installed into the local trust store on first use, and caddy trust and caddy untrust manage that.

The auto_https global option can turn parts of this off. Note that auto_https off disables certificate automation and redirects but does not make the site serve plain HTTP; disable_redirects and disable_certs turn off one part each.

Settings that affect security and reliability:

  • email: used when creating an ACME account and described as highly recommended in case of certificate problems.
  • acme_ca: sets the ACME directory. Caddy strongly recommends Let's Encrypt's staging endpoint for testing, because CA rate limits can block HTTPS access for up to a week.
  • Challenges: the HTTP challenge uses port 80 and the TLS-ALPN challenge uses port 443, both enabled by default and both requiring the port to be reachable. The DNS challenge needs DNS provider credentials and no open ports.
  • Wildcards: only a single left-most wildcard label qualifies, and Let's Encrypt requires the DNS challenge for wildcard certificates.

The DNS challenge introduces a powerful non-human credential: a DNS provider API token that can often change any record in the zone. NHI Mgmt Group recommends scoping that token to the specific zone and record type where your provider allows it, storing it outside the Caddyfile, and rotating it on a schedule. The ACME and Automated Certificate Management Guide covers the protocol, defined in RFC 8555.

On-Demand TLS and the ask endpoint

On-Demand TLS obtains certificates during the first TLS handshake that needs one, rather than at configuration load, so domain names need not be listed ahead of time. It suits platforms where customers bring their own domains.

The documentation is clear that it must be both enabled and restricted. The on_demand_tls global option configures it but does not enable it; it is enabled with the on_demand subdirective of tls. The ask setting is described as required in production to prevent abuse. Caddy sends a request with a ?domain= query; a 2xx response authorises issuance and any other status cancels it and fails the handshake.

Points to note from the documentation:

  • Restrictions are global, not per site.
  • The ask endpoint should respond in a few milliseconds and avoid DNS or other network requests.
  • The older interval and burst rate-limiting options are not recommended and should be removed.

Without an ask check, anyone who points a domain at your server can make it request certificates, consuming your CA rate limits and storage. NHI Mgmt Group recommends that the ask endpoint checks a database of verified customer domains, and that its own logs are reviewed for unexpected names.

Reverse proxy: headers and trusted proxies

The reverse_proxy documentation states that by default Caddy sets or augments X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host, passes Host through unchanged, and ignores incoming X-Forwarded-* values to prevent spoofing.

When Caddy sits behind a CDN or load balancer, you need it to trust that layer's headers. Use the trusted_proxies option with the CIDR ranges of those proxies. The documentation recommends the servers > trusted_proxies global option over the per-proxy setting, so it applies to all proxy handlers and enables client IP parsing. It warns that without correct configuration behind a CDN you may be vulnerable to spoofing of X-Forwarded-For.

The global server options add detail:

  • By default no proxies are trusted.
  • client_ip_headers defaults to X-Forwarded-For only.
  • Default parsing is left to right. trusted_proxies_strict, available since v2.8, switches to right-to-left parsing; the documentation warns that "the left-most IP address may be spoofed by the client".

Getting this right matters for every control that uses the client address: rate limits, IP allowlists, and the client IP in access logs used for detection. The Web Server Access Log Detection Guide explains why spoofed client addresses break investigations.

Header manipulation uses header_up and header_down. A - prefix deletes a header; the documentation marks header_up -*, which removes all request headers, as not recommended. NHI Mgmt Group recommends using header_down to remove headers that disclose upstream software versions, and header_up to strip any client-supplied header that your upstream treats as an identity assertion.

Upstream TLS and mutual authentication

Under transport http, upstreams addressed with https:// use TLS automatically. Since v2.11.0, the Host header is set to match the upstream when proxying to HTTPS.

The option tls_insecure_skip_verify disables certificate verification. Caddy's documentation warns that it makes the connection insecure and vulnerable to man-in-the-middle attacks, and says: "Do not use in production." Instead, use tls_trust_pool to trust the CA that issued your upstream certificates and tls_server_name to set the expected name.

For service-to-service authentication, tls_client_auth lets Caddy present a client certificate to the upstream, either an automated certificate for a domain or a static certificate and key pair. This turns Caddy into a workload with its own machine identity, which should be inventoried and rotated like any other. See the mTLS Guide.

Two smaller points from the documentation: with lb_policy cookie, the cookie value is an HMAC-SHA256 of the upstream address and the secret is an empty string if not specified, so set one; and health check requests can carry authentication through health_headers, which means those credentials also need protecting.

Server timeouts, limits and protocols

Several server defaults favour compatibility over resistance to slow-client attacks. According to the global options documentation:

OptionDocumented defaultNote from the documentation
read_body, read_headerNo timeoutA short read_body can mitigate slowloris attacks but may affect slow clients.
writeNo timeoutA small value may hurt slow clients downloading large files.
idle5 minutesApplies to keep-alive connections.
max_header_size1MBExceeding it returns 431.
protocolsh1 h2 h3Do not enable h2c unless absolutely necessary.

The strict_sni_host option requires the Host header to match the TLS SNI value and returns 421 on mismatch. It turns on automatically when client authentication is configured. NHI Mgmt Group recommends enabling it on sites that serve several hostnames with different access rules, so a client cannot present one name in TLS and request another.

On the proxy side, dial_timeout defaults to 3 seconds while response header, read and write timeouts default to no limit. NHI Mgmt Group suggests setting explicit values sized to your slowest legitimate request.

Running Caddy with least privilege

Caddy's running documentation describes the packaged service: Caddy runs as a dedicated, non-root caddy system user and group with /usr/sbin/nologin as its shell and /var/lib/caddy as its home. Root is needed only for setup tasks such as sudo caddy trust.

Sensitive files live under that home directory: certificates and state in /var/lib/caddy/.local/share/caddy, the auto-saved JSON configuration in /var/lib/caddy/.config/caddy, and the local root CA certificate under the PKI path. The automatic HTTPS documentation confirms that certificates, private keys and other assets are stored in the configured storage, which defaults to the data directory, and that instances sharing storage coordinate as a cluster. Anyone who can read this directory can impersonate your sites; anyone who can write to shared storage can affect every instance in the cluster.

For secrets such as DNS provider tokens, the documentation shows two methods: Environment= in a systemd drop-in override, or EnvironmentFile=/etc/caddy/.env to keep secrets in a separate file. NHI Mgmt Group recommends the separate file, readable only by root and the Caddy service, or a secrets manager that injects values at start. The Secrets Management Guide covers the options.

Use systemctl reload caddy for graceful reloads; the documentation warns that stopping the service to change configuration causes downtime. In Docker, named volumes for /data and /config persist certificates and state, and inside a container localhost refers to that container, not the host, which affects where the admin API is reachable from.

Logging for detection

Caddy separates the log global option, which configures named loggers with a default level of INFO, from the log directive, which configures HTTP access logs for a site. Enable access logging for every site you would need to investigate, and ship logs off the host. Because client IP fields depend on your trusted_proxies setting, verify that logged addresses are real client addresses after any change to your CDN or load balancer.

Illustrative events worth alerting on, as NHI Mgmt Group guidance: any connection to the admin endpoint from an unexpected source, configuration reloads outside a change window, repeated certificate issuance failures, and ask endpoint requests for domains that are not in your customer list.

Common failure patterns

  • Admin API on a non-loopback address. Setting admin :2019 or similar in a container or VM and exposing the port.
  • Trusting localhost as a boundary. Leaving the admin API on TCP on a shared host where other processes, or SSRF in an application, can reach it.
  • On-Demand TLS without ask. Allowing any domain to trigger certificate issuance.
  • Over-broad trusted proxies. Trusting whole provider ranges or 0.0.0.0/0, which lets clients forge their address.
  • tls_insecure_skip_verify left in production. Often added during a test and forgotten.
  • No read or write timeouts. The defaults leave room for slow-client resource exhaustion.
  • DNS tokens in the Caddyfile. Secrets committed to version control with the configuration.

Practitioner checklist

  • Set admin off, or bind the admin API to a permissioned Unix socket, on every production host.
  • Block port 2019 at the host firewall and confirm it is not published by container tooling.
  • Set an ACME account email and use the staging CA in test environments.
  • Restrict On-Demand TLS with a fast ask endpoint that checks verified domains.
  • Configure servers > trusted_proxies with only your CDN or load balancer ranges, and check logged client IPs.
  • Remove tls_insecure_skip_verify; use tls_trust_pool and tls_server_name instead.
  • Set read_header, read_body and write timeouts appropriate to your traffic.
  • Run as the unprivileged caddy user and restrict access to the data directory.
  • Keep DNS and other tokens in a protected environment file or secrets manager, scoped and rotated.
  • Enable access logs per site and forward them to central logging.

Standards and references

Related NHI Mgmt Group resources: Web Server Access Log Detection Guide · API Gateway vs Reverse Proxy · ACME and Automated Certificate Management Guide · mTLS Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.