In Caddy v2, request matching is exact-match, so a path matcher of /
for your proxy will only match requests to the root of your site and nothing else. Just remove that /
. See the request matching docs here for more detail on how it works:
You can also move the socket to the same line instead of using the to
subdirective, it reads cleaner in my opinion:
reverse_proxy unix//var/www/site/shared/tmp/sockets/puma.sock
Anyways, what you want to do is something like this:
@notStatic {
not file
}
reverse_proxy @notStatic unix//var/www/site/shared/tmp/sockets/puma.sock
This will make the reverse_proxy
only match requests when the requested path is not a file that exists on disk. You could further limit this to only requests in your public dir by adding not path /public/*
in the named matcher.
The reason for taking the approach of excluding requests to reverse_proxy
is because the default directive order for Caddyfile config has reverse_proxy
sorted before file_server
, so you either need to exclude the reverse_proxy
from handling certain requests that you want to have served statically, or you need to reorder the file_server
before reverse_proxy
and add a matcher on file_server
to only match requests to /public/*
etc.