Caddy can't read any files despite correct permissions

1. The problem I’m having:

While I have my root directory set to be global readable, Caddy is unable to so much as find anything in it, let alone try to open a file, and simply returns an empty 404 response. When file_server is set to browse, it complains that it’s unable to get info about directory entries for any file in the directory.

I suspect this might be something to do with SELinux, but I’m at an absolute loss as to what to do to fix it.

2. Error messages and/or full log output:

Oct 11 21:23:49 manebridge caddy[677]: {"level":"debug","ts":1697059429.8107429,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/var/www/html","request_path":"/","result":"/var/www/html"}
Oct 11 21:23:49 manebridge caddy[677]: {"level":"debug","ts":1697059429.8113945,"logger":"http.handlers.file_server","msg":"no index file in directory","path":"/var/www/html","index_filenames":["index.html","index.txt"]}
Oct 11 21:23:49 manebridge caddy[677]: {"level":"debug","ts":1697059429.8114512,"logger":"http.handlers.file_server","msg":"browse enabled; listing directory contents","path":"/var/www/html","root":"/var/www/html"}
Oct 11 21:23:49 manebridge caddy[677]: {"level":"error","ts":1697059429.8116152,"logger":"http.handlers.file_server","msg":"could not get info about directory entry","name":"index.html","root":"/var/www/html"}
Oct 11 21:23:49 manebridge caddy[677]: {"level":"error","ts":1697059429.811812,"logger":"http.handlers.file_server","msg":"could not get info about directory entry","name":"index.css","root":"/var/www/html"}
Oct 11 21:23:49 manebridge caddy[677]: {"level":"error","ts":1697059429.8119562,"logger":"http.handlers.file_server","msg":"could not get info about directory entry","name":"test.txt","root":"/var/www/html"}

3. Caddy version:

v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=

4. How I installed and ran Caddy:

Install — Caddy Documentation + systemd

a. System environment:

Rocky Linux 9.2 on a 1GB Linode (so x64)

b. Command:

/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

Entirely unaltered from default.

d. My complete Caddy config: {
	root * /var/www/html
	file_server browse

Thanks in advance for any help!

Rocky is Red Hat based, right? Do you have SELinux enabled? If so, it may be preventing access to the files. You may need to adjust the SELinux rules to allow Caddy to read those files.

See Investigate whether SELinux rules need to be added for rpm · Issue #95 · caddyserver/dist · GitHub for more context.

1 Like

You are correct about Rocky being a RHEL derivative. And as it turns out, your guess (and mine) was right - that was exactly what was going on. Now to find the time to apply a better fix than just setting everything to permissive …

Thank you for pointing me in the right direction! :slight_smile:


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