I have some questions about the combined use of handle and file_server

I have some questions about the combined use of handle and file_server

first, I use the following configuration, it is normal and I can start my service normally

when I visit in browser (https://127.0.0.1:8019) ,it’s work:

but, when I use handle to add a prefix match, it doesn’t work.

configuration:

when I visit in browser (https://127.0.0.1:8019/v2/x) ,it’s doesn’t work:

Error message HTTP ERROR 404

Can you tell me why this is and how to solve it? Thank you

Please don’t screenshot config, instead write it as code blocks in your post so we can quote it. Please fill out the help topic template as per the forum rules.

You might be looking for handle_path rather than handle for this usecase.

When Caddy does a file lookup (for try_files or file_server), it takes the current request path and appends it to root. So if your /var directory doesn’t have a /v2 directory in it then it won’t find anything.

Using handle_path strips the matched path prefix from the request path before moving on, so /v2 wouldn’t need to exist on disk.

2 Likes

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