Caddy Static Site Configuration

Caddy's file_server directive makes serving static sites trivially easy. Combine it with encode gzip brotli and you get compressed responses without any extra configuration.

A complete static Caddyfile

file_server serves the directory; encode compresses responses.

example.com {
    root * /var/www/example.com
    encode zstd gzip
    file_server
}

SPA fallback

Add try_files {path} /index.html before file_server to route unknown paths to a single-page app.

Open the Static site generator

Frequently asked questions

Does Caddy compress by default?

No. Add the encode directive to enable zstd and gzip.

How do I hide dotfiles?

Use a matcher with respond @dotfiles 404 or a file_server hide list so paths like /.git are not served.

Guides