File listing from subfolder

The problem I’m having:

I’m testing caddy in a local machine that I reach at

http://webserver.network.local

and it serves a static website generated with hugo.

I’m trying to serve a file listing from a subdirectory of the domain.
I want to serve some static files from

http://webserver.network.local/packages

with a directory listing, but I keep getting 404 when trying to access it. The hugo site works normally.

Caddy version:

caddy 2.6.2

How I installed and ran Caddy:

caddy was installed as a system package and runs from systemctl

System environment:

the server runs Debian 13.4 with systemd

Command:

systemctl start caddy

My complete Caddy config:

:80 {
handle /packages/ {
root * /var/www/html/packages
file_server {
browse
}
}
root * /var/www/html
file_server
}

I’ve always used apache, but wanted to try caddy. I feel like I’m missing something, because I’m sure this is trivial to obtain.

Thanks in advance for your help

  1. You should upgrade Caddy, the version you’re running is quite outdated.

  2. Make sure the Caddy user has the proper permissions to access and read the contents of /var/www/html/packages.

  3. Check your Caddy logs, and consider enabling debug mode. You will likely find more detailed information there that can help with your current issue.

thanks a lot, I’ve updated caddy with its own repository, which is more up to date than the standard debian package is.

I’ve also learned about debug mode, which I didn’t know existed :grin:

My caddyfile is now:

:80 {
	handle /packages/* {
		file_server {
			browse
		}
	}
	root * /var/www/html
	file_server
}

and it works if I point my browser at

http://webserver.network.local/packages/

but it won’t add the final slash, so if I go to

http://webserver.network.local/packages

In this latter case, it will still throw a 404.

But this is a minor issue for me.

Thanks a lot for your help