Caddy command / Caddyfile update to v2

1. Caddy version (caddy version):

Caddy v1 but moving to Caddy v2

2. How I run Caddy:

I am using the github project - https://github.com/lensesio/schema-registry-ui to manage Kafka schema registry. We have it set up as a docker container - https://hub.docker.com/r/landoop/schema-registry-ui/builds. Unfortunately, Caddy v1 has been deemed a security risk so we are trying to update to Caddy v2.

a. System environment:

alpine 3.7 (docker container)

b. Command:

V1 COMMAND:
exec /caddy/caddy -conf /caddy/Caddyfile

V2 COMMAND:
exec /caddy/caddy run --conf /caddy/Caddyfile

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

----------------------------------------------
V1 CONFIG:
0.0.0.0:8000
tls off

root /schema-registry-ui
log /access.log

proxy /api/schema-registry http://IP_ADDRESS:8081/ {
       without /api/schema-registry
}
----------------------------------------------
V2 CONFIG:
{
    auto_https off
}

0.0.0.0:8000

root * /schema-registry-ui
log

reverse_proxy /api/schema-registry/* http://IP_ADDRESS:8081
----------------------------------------------

3. The problem I’m having:

I am trying to update the run command and the config file so that they are converted to Caddy v2

4. Error messages and/or full log output:

5. What I already tried:

A lot of config updates / caddy command changes

6. Links to relevant resources:

So what’s the problem exactly? What isn’t working?

Did you read the upgrade guide?

I am trying to upgrade to Caddy v1 to v2 so I am trying to update the Caddyfile (while going through the upgrade doc). The current error I am getting is “Client sent an HTTP request to an HTTPS server.” I thought that the “auto_https off” would fix it.

A part of the problem is that I don’t exactly understand what is trying to be done in the v1 config I posted above (not my github project)… I assume it is a reverse proxy connecting to the api of schema registry - I am trying to take the exact v1 config and translate it to v2

Try using http://:8000 for your site label instead of 0.0.0.0:8000 if you specifically want HTTP on port 8000.

Yes, that appears to be the behaviour of the v1 config.

It takes any request for /api/schema-registry, strips that prefix from the URI, and sends it upstream.

Stripping the prefix in v1 was function of the proxy directive out of necessity (if you couldn’t do it in the proxy, it was exceedingly difficult to do it otherwise). In v2 this functionality doesn’t need to be part of the reverse proxy module because you can rewrite the URI yourself first. This is touched on in the v2 upgrade guide, under the proxy heading: Upgrading to Caddy 2 — Caddy Documentation

A common config pattern for this purpose looks like:

route /<prefix>* {
  uri strip_prefix /<prefix>
  reverse_proxy <upstream>
}

Or a slightly more convenient way:

handle_path /<prefix>* {
  reverse_proxy <upstream>
}

As handle_path implicitly strips the prefix for you.

reverse_proxy (Caddyfile directive) — Caddy Documentation
route (Caddyfile directive) — Caddy Documentation
handle_path (Caddyfile directive) — Caddy Documentation

2 Likes

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