Server error when running behind Caddy

Hi there,
I am trying to set up Plone with Caddy as reverse proxy so that I do not have to worry too much about renewing let's encrypt certificates. I based the set up on nginx, Frontend, Backend, PostgreSQL container example — Plone Documentation v6 and replaced the nginx config with a Caddyfile. As soon as I a request goes through Caddy, the start page briefly displays and is very quickly replaced with a server error. When accessing the frontend directly on port 3000, everything works just fine. Thus I think it has to do with my caddy configuration, but I struggle to debug the problem as there simply is no error entry in the logs.

My Caddyfile looks like this

(cloudflare) {
  tls {
    dns cloudflare ---api-key---
  }
}

---hostname--- {
  handle_path /++api++* {
    @apiPath path_regexp apiPath ^/(\+\+api\+\+\/?)+($|/.*)
    rewrite @apiPath /VirtualHostBase/https/{host}/Plone/++api++/VirtualHostRoot/{http.matchers.path.re.apiPath.2}
    reverse_proxy backend:8080
  }

  @staticAssets path *.js *.jsx *.css *.less *.swf *.eot *.ttf *.otf *.woff *.woff2
  @staticImages path_regexp staticImages ^/static.*\.(ico|jpg|jpeg|png|gif|svg)$

  header @staticAssets Cache-Control "public"
  header @staticAssets Expires {http.now.plus.31536000s}

  reverse_proxy @staticAssets frontend:3000
  reverse_proxy @staticImages frontend:3000

  reverse_proxy frontend:3000
  import cloudflare
}

(replaced api key and hostname)

So I would have two questions:

  1. does anyone run a Caddy setup and would be willing to share their config?
  2. how can I debug this error? The docker logs do not expose any error message, all requests are being returned with a 200 status.

Thanks in advance!

Okay, I found the error. I had to move the path_regexp expression out of the handle_path block. The Caddyfile now looks like this:

---hostname--- {
  @apiPath path_regexp apiPath ^/(\+\+api\+\+\/?)+($|/.*)
  handle @apiPath {
    rewrite @apiPath /VirtualHostBase/https/{host}/Plone/++api++/VirtualHostRoot/{re.apiPath.2}
    reverse_proxy backend:8080
  }

  @staticAssets path *.js *.jsx *.css *.less *.swf *.eot *.ttf *.otf *.woff *.woff2
  @staticImages path_regexp staticImages ^/static.*\.(ico|jpg|jpeg|png|gif|svg)$

  header @staticAssets Cache-Control "public"
  header @staticAssets Expires {http.now.plus.31536000s}

  reverse_proxy @staticAssets frontend:3000
  reverse_proxy @staticImages frontend:3000

  reverse_proxy frontend:3000
  import cloudflare
}

Now the site works. But this was pretty tricky to debug because it actually appears as if there was only a lack of log lines in the logs of the backend (because the API requests were not rewritten at all and thus not forwarded to the backend).

Anyway, I hope this is helpful to others.

2 Likes