Caddy Security Headers Configuration

Caddy's header directive makes it straightforward to inject HTTP security headers on every response. Generate the correct header block for your security policy here.

A header block

Caddy sets response headers with the header directive; prefix a name with - to remove one.

example.com {
    header {
        Strict-Transport-Security "max-age=63072000; includeSubDomains"
        X-Content-Type-Options nosniff
        Referrer-Policy strict-origin-when-cross-origin
        -Server
    }
}

Content-Security-Policy

CSP is the header that needs the most care. Start report-only, watch for violations, then enforce.

Open the Security headers generator

Frequently asked questions

Are headers applied to error responses?

Yes, header applies to all responses from that site unless you scope it with a matcher.

Guides