Internal network file browse for root only while public network browsing only for all directories

1. The problem I’m having:

Only allowing the public network to browse files inside sub-directories while keeping the root directory only viewable to the internal network. I think my handle match for sub-directories is wrong but I saw it working for tries before it started to come up with blank pages.

2. Error messages and/or full log output:

N/A

3. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

Installed via official docker container

a. System environment:

Docker

b. Command:

N/A

c. Service/unit/compose file:

N/A

d. My complete Caddy config:

(internal-only) {
    @public_networks not remote_ip 192.168.30.0/16
    respond @public_networks "Access Denied" 403 {
            close
    }
}

link.abc.dev {

	root * /LINK

	handle /%*/* {
		file_server {
			browse
		}
	}
	
	handle / {
		import internal-only
		file_server {
			browse
		}
	}

}

5. Links to relevant resources:

N/A

Any help solving this puzzle is greatly appreciated. Thank you!

You can probably do:

	handle / {
		import internal-only
		file_server browse
	}

	handle {
		file_server browse
	}

Using no matcher means “match anything”. A matcher of / will happen first.

That worked. Thank you sir!

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