File_server returning 404 incorrectly

1. The problem I’m having:

Trying to host a static site. It was working last month something change (I’m not sure what, I know, that’s not real helpful) and now it’s not working. I have several sites hosted via caddy and the other ones are working (even other static file sites).

curl -vL https://kinson.cloud

+0[192.168.8.22:~]$ curl -vL https://kinson.cloud
* Host kinson.cloud:443 was resolved.
* IPv6: (none)
* IPv4: 89.116.212.63
*   Trying 89.116.212.63:443...
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: none
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 / x25519 / id-ecPublicKey
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=kinson.cloud
*  start date: Jan 28 20:06:11 2025 GMT
*  expire date: Apr 28 20:06:10 2025 GMT
*  subjectAltName: host "kinson.cloud" matched cert's "kinson.cloud"
*  issuer: C=US; O=Let's Encrypt; CN=E6
*  SSL certificate verify ok.
*   Certificate level 0: Public key type EC/prime256v1 (256/128 Bits/secBits), signed using ecdsa-with-SHA384
*   Certificate level 1: Public key type EC/secp384r1 (384/192 Bits/secBits), signed using sha256WithRSAEncryption
*   Certificate level 2: Public key type RSA (4096/152 Bits/secBits), signed using sha256WithRSAEncryption
* Connected to kinson.cloud (89.116.212.63) port 443
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://kinson.cloud/
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: kinson.cloud]
* [HTTP/2] [1] [:path: /]
* [HTTP/2] [1] [user-agent: curl/8.12.1]
* [HTTP/2] [1] [accept: */*]
> GET / HTTP/2
> Host: kinson.cloud
> User-Agent: curl/8.12.1
> Accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Request completely sent off
< HTTP/2 404
< alt-svc: h3=":443"; ma=2592000
< server: Caddy
< content-length: 0
< date: Tue, 11 Mar 2025 06:27:26 GMT
<
* Connection #0 to host kinson.cloud left intact

2. Error messages and/or full log output:

{"level":"debug","ts":1741674420.2001913,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/var/www/kinson.cloud","fs":"","request_path":"/","result":"/var/www/kinson.cloud"}
{"level":"debug","ts":1741674420.2003028,"logger":"http.handlers.file_server","msg":"no index file in directory","path":"/var/www/kinson.cloud","index_filenames":["index.html","index.txt"]}
{"level":"debug","ts":1741674420.2003903,"logger":"http.log.error.log0","msg":"{id=ahzxmd4dh} fileserver.(*FileServer).notFound (staticfiles.go:651): HTTP 404","request":{"remote_ip":"<my-ip>","remote_port":"44843","client_ip":"<my-ip>","proto":"HTTP/2.0","method":"GET","host":"kinson.cloud","uri":"/","headers":{"User-Agent":["curl/8.12.1"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"kinson.cloud"}},"duration":0.000313524,"status":404,"err_id":"ahzxmd4dh","err_trace":"fileserver.(*FileServer).notFound (staticfiles.go:651)"}

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

apt on Ubuntu 24.04.1 LTS

a. System environment:

d. My complete Caddy config:

{
	admin :2024
	
	servers {
		metrics	
	}
	log {
		output file /var/log/caddy/main.log
		format json
		level debug
	}
}


import sites-enabled/*

wg.kinson.cloud {
	reverse_proxy :6789
}

dns.kinson.cloud {
	reverse_proxy :5380
}

matrix.kinson.cloud, matrix.kinson.cloud:8448 {
	reverse_proxy /_matrix/* 127.0.0.1:6167
}

kinson.cloud {
	# matrix client/server delegation
	handle_path /.well-known/matrix/* {
		header Access-Control-Allow-Origin *
		header Content-Type "application/json"
		header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
		header Access-Control-Allow-Headers "X-Requested-With, Content-Type, Authorization"

		respond /client `{
			"m.server": {"base_url":"https://matrix.kinson.cloud"},
			"m.homeserver": {"base_url":"https://matrix.kinson.cloud"},
			"org.matrix.msc3575.proxy": {"url": "https://matrix.kinson.cloud"}
		}`
		respond /server {"m.server":"matrix.kinson.cloud:443"}

		# Respond with 404 if not /client or /server
		respond 404
	}

	handle_path /matrix_assets/* {
		# need backgroud.jpg (close to 1080p)
		# need logo.svg
		root * /var/www/matrix_assets/
		file_server
	}

	handle_path /* {
		root * /var/www/kinson.cloud
		file_server
	}
	log {
		output file /var/log/caddy/kinson.cloud.log
		level debug
		format json
	}
}

chat.kinson.cloud {
	header X-Frame-Options SAMEORIGIN
	header X-Content-Type-Options nosniff
	header X-XSS-Protection "1; mode=block"
	header Content-Security-Policy "frame-ancestors 'self'"
	
	reverse_proxy :8009
}

The relevant directory

$ ls /var/www/kinson.cloud/ -la
total 20
drwxrwxr-- 2 linuxadmin linuxadmin 4096 Aug  2  2024 .
drwxr-xr-x 8 gitactions linuxadmin 4096 Mar  6 23:33 ..
-rw-r--r-- 1 linuxadmin linuxadmin  948 Aug  2  2024 index.html
-rw-r--r-- 1 linuxadmin linuxadmin  573 Aug  2  2024 main.js
-rw-r--r-- 1 linuxadmin linuxadmin 2013 Aug  2  2024 style.css

My best guess is that the issue is with the file permissions of your /var/www/kinson.cloud/ folder.

Do you know which user your Caddy server is running as? It might not have permission to read the contents of /var/www/kinson.cloud/.

As a quick test, try running:

chmod 775 /var/www/kinson.cloud/

Then test again and see if it works.

Edit: Just to clarify, your current permissions on /var/www/kinson.cloud/ are 774, which isn’t enough unless Caddy is running as linuxadmin or root, or if it’s a member of those groups. Changing it to 775 (r and x for “others”) will allow Caddy to enter the folder if it’s running as another user.

2 Likes

Ah, it it running as user caddy! (Checked the systemd unit in case any future travelers happen here)

Running chmod 775 -R /var/www/kinson.cloud fixed it!

2 Likes