Caddy file server browse not working

Hi, I am a new baby here, something is really confuse me when I specify the root for file_server, for example

1. Caddy version (caddy version):


2. How I run Caddy:

Caddyfile {
        handle /files/* {
                file_server browse {
                       root ./asset

my directory

ubuntu:~/code/caddy$ tree
├── asset
│   ├── name.wav
│   ├──
├── caddy
├── Caddyfile

a. System environment:


b. Command:

./caddy start

When I enter, I expect I could get a file explorer page, but actually nothing. when I delete handle /files/* { and visit, everything works fine

according to Caddy file server browse not working when root a specific directory,

	handle_path /files* {
		root * /asset
		file_server browse

works, but the following snippet won’t work and I still don’t know why

	handle /files* {
		root * /asset
		file_server browse


	file_server /files* browse {
			root * ./asset

I try to visit or, I get a blank page

You used a matcher of /files/* which does not match /files. You would need to use a /files* matcher instead to match that path.

The handle_path directive strips the given matcher from the request path before continuing. handle does not.

So for example with a request like /files/foo.txt, when file_server assembles the path, it looks for files at ./asset/files/foo.txt for example, instead of /asset/foo.txt, because /files doesn’t get removed by handle.


hi, thx for your reply!! it solve my problem!!

I change /files/* to /files* according to your advice {
	handle /files* {
		root * /asset
		file_server browse

according to

because /files doesn’t get removed by handle .

so visit actually visit ./asset/files directory (so I need to create files dir inside asset dir, it works, but it also means I can only visit file inside ./asset/files, there is no way to visit ./asset/foo.txt unless I change handle to handle_path )

visit doesn’t get ./asset/ because it only handle files*

Yeah, essentially.

Is there a question hiding in there, or are you just recapping for yourself? Just making sure everything is clear

just recapping for myself, thx!

1 Like

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