Caddy can manage response headers through a Caddyfile header directive. Keep each rule close to the response type it is meant to control.
A small baseline
example.com {
header {
>X-Content-Type-Options "nosniff"
>Referrer-Policy "strict-origin-when-cross-origin"
}
root * /var/www/example
file_server
}
Replace the domain and filesystem path with your own. The leading > sets the field with deferred execution, when the response is written. This helps the intended value apply after a downstream handler has produced the response.
Choose the header operation
A plain field sets a value. + adds another value, - deletes a field, and ? sets a default only if absent. Choose deliberately: an extra CSP or CORS origin is not equivalent to replacing a policy.
Use request matchers when rules should apply to selected paths. Avoid giving private pages the long-lived caching policy intended for versioned assets.
HTTPS and HSTS
Caddy's automatic HTTPS and HTTP redirects do not replace a deliberate HSTS rollout. Verify certificates and any subdomain scope before choosing an HSTS lifetime. See the HTTPS guide.
Validate and inspect
caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
Use your actual config path. After validation, reload through your normal administration process and inspect representative public responses, especially when a reverse proxy or CDN sits in front of Caddy.