The issue is that the reverse_proxy is handling all requests before it reaches file_server. Caddy doesn’t know otherwise which requests should avoid using the proxy and which should be handled via the file server.
When using the Caddyfile, directives are handled in a specific order, described in the following docs page. Specifically, reverse_proxy is ordered higher than file_server, so it’ll get handled first if a request matched by it (most directives match all requests by default).
To solve this, you’ll need to use a named matcher that excludes the reverse_proxy directive from handling requests to /static/*.
It’ll look something like this:
@notStatic {
not path /static/*
}
reverse_proxy @notStatic 127.0.0.1:9000
Thanks for detailed explanation, so I followed the approach and now request for static assets is not giving any errors but assets are still not getting delivered to client.
In client, returned js/css files are empty but I have checked the path and files are there and non-empty so not sure what I am doing wrong here. Any help would be appreciated.
And I running caddy as root so caddy would have access to all the files too.
You need to use the root directive like you did in your original post. file_server doesn’t take the path as the first argument (it should probably warn though, that’s a minor parsing bug).