Help converting v2 caddyfile to v1

I’m still on Caddy V1 because I’m using reauth plugin extensively and I don’t believe there is a working version yet for V2.

Anyhow, this sample V2 caddyfile is in the documentation for a project (BlueMap for Minecraft) that I’d like to use.

Is it possibe to convert this to V1?

bluemap.domain.dk {
  root C:\AMPDatastore\Instances\Minecraft\Minecraft\bluemap\web
  file_server

  #reverse_proxy /live/*  http://127.0.0.1:8100

  @JSONgz {
    path *.json
    file {
      try_files {path}.gz
    }
  }

  route @JSONgz {
    rewrite {http.matchers.file.relative}
    header Content-Type application/json
    header Content-Encoding gzip
  }

}

You’ve got some logic there:

  • Looking for .json files
  • Checking for a gzip sidecar
  • Rewriting to it if both the above are true
  • Then appending headers in the same circumstance

You really don’t have that kind of flexibility in Caddy v1. You can get really, disgustingly hacky with rewrites as conditionals, prepending arbitrary path prefixes and then proxying to get rid of them again. You can abuse entire site blocks as a kind of v2 route analogue this way.

That said, it’s still nearly impossible to stack conditionals that otherwise can’t be stacked in a single directive in Caddy v1; you can only ever do one rewrite per request per site block. If you rewrite first to check that the file exists, you lose the ability to rewrite to prepend the arbitrary prefix. If you rewrite to prepend the prefix, you’re not checking whether the file actually exists or not, because rewriting is the mechanism for practically checking file existence in v1.

I gave up after a few minutes. I’d hesitate to rule out the possibility of another old Caddy v1 veteran to upstage my rewrite hacks here and come out with a working config, but that’s a pretty small list. v1 just isn’t as powerful or flexible as v2.


My recommendation is to use Caddy v2 as your upstream server, with this logic applied, and then simply reverse proxy to it from Caddy v1 with reauth if that’s your requirement.

1 Like

Excellent advise, thank you so much :smile:

I did just that and it works perfectly - until reauth2 or an alternative is a reality.

This topic was automatically closed after 30 days. New replies are no longer allowed.