Need help migrating to Caddyfile v2 from Caddyfile v1

You’re right, that looks correct. @matt, possible bug on index

I’m seeing this error:

adapt: parsing caddyfile tokens for 'file_server': Caddyfile:4 - Error during parsing: Wrong argument count or unexpected line ending after 'default.txt'

I think the v2 approach for this would be:

try_files {path} default.txt

This should serve a file at the requested path if it exists, otherwise it defaults to default.txt, if I’m understanding what you’re trying to achieve.

You would use a matcher to exclude the the path. In v2, matchers are the primary way to implement conditional behaviour.

@notStatic {
    not {
        path /static/*
    }
}
reverse_proxy @notStatic 127.0.0.1:8010

The reverse_proxy has the subdirective transport which contains some timeout options. See reverse_proxy (Caddyfile directive) — Caddy Documentation

@notStatic {
    not {
        path /static/*
    }
}
reverse_proxy @notStatic 127.0.0.1:8010 {
    transport http {
        dial_timeout 30s
        tls_timeout 10s
    }
}

The direct equivalents to timeouts from Caddy v1 isn’t yet available in the Caddyfile, but it should be very soon (next few days or weeks). For now, they’re configurable via JSON. See JSON Config Structure - Caddy Documentation

			"read_timeout": 0,
			"read_header_timeout": 0,
			"write_timeout": 0,
			"idle_timeout": 0,

For now, they’re defaults are no timeout.

The basicauth directive! :stuck_out_tongue: https://caddyserver.com/docs/caddyfile/directives/basicauth

It doesn’t support plaintext passwords anymore, you can use the caddy hash-password command to hash the password for you.

basicauth /secure/* {
	username JDJhJDEwJEVCNmdaNEg2Ti5iejRMYkF3MFZhZ3VtV3E1SzBWZEZ5Q3VWc0tzOEJwZE9TaFlZdEVkZDhX
}

Unfortunately, that’s still up in the air, hasn’t been totally determined how it’ll look in the Caddyfile. Should be figured out very soon though. The discussion so far seems to point to it looking something like:

handle_errors {
    @404 {
        # some matcher on the response code, TBD
    }
    rewrite @404 404.html
}

Doing this is possible in JSON currently using the "errors" key in a server block: JSON Config Structure - Caddy Documentation

The redir directive! :stuck_out_tongue: redir (Caddyfile directive) — Caddy Documentation

redir /movies/* https://othersite.com 302
redir /2015/04/18/* /software/ 302
3 Likes