When request URL is aruiplex.com, Caddy can show me the index.html in /srv directory.
When request URL is aruiplex.com/files, Caddy can show me the file list in the /files directory in docker container.
When request URL is aruiplex.com/api, Caddy can pass this request to localhost:7022.
But when I request aruiplex.com/files file server is not working, it gives me a 404. And I have check this directory in docker container, there have some files.
Are you making a request to /files, or to /files/? You matcher is /files/* so only /files/ would match, of those two. You could change it to /files* which would match both, but then /filesssss would also match, FYI.
The way file_server works, Caddy will take the request path, and append it to the defined root, then look for files on disk at that location. So that means for a root of /files and request path of /files/example.txt it would look at /files/files/example.txt. You can see that /files is duplicated here. So you’d need to strip the /files prefix from the path before passing it to file_server for it to work. This can be done with handle_path, which has built-in path stripping logic.
Very thank you! I changed my question to make it easier to understand. You totally answered my question and even show me the logic behind, and I am very clear now. Thank you very much again!