Listing of sub-directories

1. The problem I’m having:

Hi. I have a file_server setup with caddy. I have a public/ directory, which has browse enabled. Now I want to have directory x/ where browse isn’t enabled, but it is enabled for each subdirectory.

vault.chamik.eu/public/ → browsing
vault.chamik.eu/x/no browsing
vault.chamik.eu/x/hello/ → browsing

I figured out the /public/ part, I have trouble with setting up the /x/path.

2. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

Using the official docs for Debian.

a. System environment:

Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye

b. Command:

systemctl start caddy

d. My complete Caddy config:

vault.chamik.eu {
    root * /www/vault.chamik.eu

    file_server
    file_server /public/* {
        browse
    }
}

Howdy @chamik, welcome to the Caddy community.

When you have multiple directives with path matchers, Caddy will always try to pick the one with the longer (i.e. most specific) path that applies.

That means you should be able to simply specify the longer path that overrides the behaviour you want.

So, for:

You might be served simply by configuring:

file_server /public/* {
  browse
}

file_server /x/*

file_server /x/*/* {
  browse
}

Alternatively, if you want to be very sure that these areas are handled exclusively, you can take advantage of the handle directive and matchers:

@browse path /public/* /x/*/*
@nobrowse path /x/*

handle @browse {
  file_server {
    browse
  }
}

handle @nobrowse {
  file_server
}
2 Likes

Also, it can be slightly simplified with file_server browse (i.e. inline the browse option). If you do need to configure other options though, you do need the long-way.

2 Likes

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