Using headers and others globally

Right now I have: {
         log /var/log/caddy/rom-quark-business.log {
                 rotate {
                 size 5  # Rotate after 5 MB
                 age  30 # Keep log files for 30 days
                 keep 2  # Keep at most 2 log files
         header / {
                 Strict-Transport-Security "max-age=31536000"
                 X-XSS-Protection "1; mode=block"
                 X-Content-Type-Options "nosniff"
                 X-Frame-Options "DENY"
         tls {
                 key_type rsa4096
         root /var/www/html

Is it possible to take the header, tls, and even log section out, and make it a global setting (somehow using host variables on the log one), or do I need to repeat the same for each host?

@Fastidious all the directives are server based so currently you will need to repeat each for every server declaration

1 Like

Notable exception is timeouts which Caddy is unable to set on a per-host (server) basis.

So, that one is set at the top, outside any server declaration, correct? Is there any other? Thanks!

timeouts has a slightly unique behaviour as far as I’m aware; you still declare it inside a server block, but the lowest value amongst all declared servers in a Caddyfile is applied universally. It’s recommended to only apply it once for simplicity.

1 Like

No, never do this. The first line of the Caddyfile is always the address of the site to serve.

1 Like

That rule, at least, is inviolate. :slight_smile:

Interesting idea, but I am looking for minimise. Adding yet another file to maintain goes against that aim. Thanks for the tip, though!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.