File_server browse + sidecar files

1. The problem I’m having:

Hi, just wanted to ask if the file-server module handles sidecar file if directory browsing is enabled.

The following url has two index files also saved as gz. How can I tell if caddy serves the gzip version instead of the text version?

https://mirrors.tnonline.net/gentoo/gentoo-distfiles/

2. Error messages and/or full log output:

{"level":"info","ts":1694443634.8850532,"logger":"http.log.access.log14","msg":"handled request","request":{"remote_ip":"192.168.0.132","remote_port":"45394","client_ip":"192.168.0.132","proto":"HTTP/2.0","method":"GET","host":"mirrors.tnonline.net","uri":"/gentoo/gentoo-distfiles/filelist.txt","headers":{"Sec-Fetch-Site":["same-origin"],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en-GB,en-us;q=0.9,en;q=0.8"],"If-None-Match":["\"s0tg6m1n51n\""],"Sec-Ch-Ua-Mobile":["?1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Referer":["https://mirrors.tnonline.net/gentoo/gentoo-distfiles/"],"If-Modified-Since":["Mon, 11 Sep 2023 10:08:46 GMT"],"Sec-Ch-Ua":["\" Not;A Brand\";v=\"99\", \"Chromium\";v=\"115\", \"OperaMobile\";v=\"77\", \"Opera\";v=\"101\""],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Linux; Android 13; SM-S908B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.5790.167 Mobile Safari/537.36 OPR/77.1.4095.74475"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"Android\""]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"mirrors.tnonline.net"}},"bytes_read":0,"user_id":"","duration":0.109694813,"size":2759402,"status":200,"resp_headers":{"Vary":["Accept-Encoding"],"Content-Type":["text/plain; charset=utf-8"],"Last-Modified":["Mon, 11 Sep 2023 14:07:16 GMT"],"Accept-Ranges":["bytes"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"X-Frame-Options":["DENY"],"Strict-Transport-Security":["max-age=31968000; preload"],"Content-Encoding":["gzip"],"Server":["Caddy"],"Etag":["\"s0tr841n562\""]}}

3. Caddy version:

I compiled caddy from git master branch yesterday. I modified the browse.go to allow for 100k files instead of 10k files, but otherwise it is as master branch.

v2.7.4 => /usr/src/caddy/git/caddy@(devel)

4. How I installed and ran Caddy:

a. System environment:

Gentoo Linux, amd64
Kernel 6.4.12
Using OpenRC as init system.

d. My complete Caddy config:

mirrors.tnonline.net:443 {
	tls /etc/letsencrypt/live/mirrors.tnonline.net/fullchain.pem /etc/letsencrypt/live/mirrors.tnonline.net/privkey.pem {
		curves x25519 secp521r1 secp384r1 secp256r1
	}
	log {
		output file /var/log/caddy/mirrors.tnonline.net_443.log {
			roll_size 100MiB
			roll_keep_for 100d
		}
		format json
	}
	encode zstd br gzip
	root * /var/www/domains/mirrors.tnonline.net/
	
	@redirect {
		not file {
			try_files {path} {path}/
		}
	}

	@nobrowse {
		not path /.well-known/
		not path /resources/*
		not path /res/
		not path /index.php
	}

	@cache {
		path /favicon.ico
		path /img/*.*
		path /res/*.*
	}

	route {
		header {
			Strict-Transport-Security "max-age=31968000; preload"
			X-Frame-Options DENY
#			Cache-Control "max-age=1800"
		}
		header @cache {
			Strict-Transport-Security "max-age=31968000; preload"
			X-Frame-Options DENY
			Cache-Control max-age=604800
			# Cache-Control "max-age=31536000"
		}
	}

	file_server @nobrowse {
		browse /www/mirrors.tnonline.net/res/browse.html
		hide /robots.txt /sitemap.txt /index.php /.well-known /resources /favicon.ico /res
		precompressed br zstd gzip
	}
}

mirrors.tnonline.net:80 {
	log {
		output file /var/log/caddy/mirrors.tnonline.net_80.log {
			roll_size 100MiB
			roll_keep_for 100d
		}
		format json
	}
	root * /var/www/domains/mirrors.tnonline.net/
	file_server
	@https not path /.well-known/*
	redir @https https://mirrors.tnonline.net/ permanent
}

5. Links to relevant resources:

Update. I did an strace on the caddy server and it does appear as the sidecar file is indeed used.

This is short abreviated snippet from strace log:

81963 16:56:18.294395 read(44</var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distf81962 16:56:17.742541 newfstatat(AT_FDCWD</>, "/var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distfiles/filelist.html",  <unfinished ...>
81962 16:56:17.742624 newfstatat(AT_FDCWD</>, "/var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distfiles/filelist.html.br",  <unfinished ...>
81962 16:56:17.766667 newfstatat(AT_FDCWD</>, "/var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distfiles/filelist.html.gz",  <unfinished ...>
81962 16:56:17.766802 openat(AT_FDCWD</>, "/var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distfiles/filelist.html.gz", O_RDONLY|O_CLOEXEC <unfinished ...>
81962 16:56:17.766869 <... openat resumed>) = 44</var/www/domains/mirrors.tnonline.net/gentoo/gentoo-distfiles/filelist.html.gz>

Is it possible to add sidecar files to the log, when they are matched and used?

Add the debug global option, you’ll see more detail about what file_server is doing.

And yes, browse only affects requests to directories, and doesn’t change how requests to specific files are handled.

1 Like

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