Setting headers for specific extensions seems impossible

Hey folks - really liking Caddy, and while I’m not a huge fan of the configuration syntax, I’ve mostly been able to replicate the nginx config I had before, such that Caddy is now powering the extremely popular Emacs package site melpa.org.

One issue I hit today, though, is that I can’t figure out how to set Cache-Control headers only for certain file types: our Nginx config had something like this:

location ~ ^/packages/.*\.svg {
  add_header Cache-Control no-cache;
}

The closest I can find for Caddy is the “header” directive, which appears to provide only prefix matching for a subpath. Neither the docs nor the tests indicate that there is wildcard or regexp support.

Any idea how I can achieve this with Caddy? Thanks in advance!

1 Like

This is not possible for now. Except the svgs are gonna be in a dedicated directory.

2 Likes

Argh! That’s what I feared. Will have to review my options… :frowning:

The solution I used was rewrite + proxy on localhost. Might be a solution for you too:

Thanks. In the end, we’re back on nginx. We saw erratic errors and stalling with Caddy, some of which were likely due to clashes with Emacs’ URL quirky library, and we didn’t know where to start figuring out what the problem was.

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