CGit: Unknown file or directory

1. Caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I installed, and run Caddy:

a. System environment:

Systemd, RPI4, Ubuntu Server

b. Command:

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

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

{
	https_port 443
	admin off
	order cgi before respond
}

chonkyrabbit.eu {
	encode zstd gzip

	# Website
	handle_path / {
		php_fastcgi unix//var/run/php/php8.1-fpm.sock
		try_files {path} /index.html /index.php =404
		root * /var/www/html
		file_server
	}
	handle_path /data/* {
		root * /var/www/html/data
		file_server
	}

	# Private Fileserver
	handle_path /files* {
		root * /var/www/ftp/public
		file_server {
			hide _*
			browse
		}
	}

	# Public Fileserver
	route /filebin* {
       	reverse_proxy localhost:8000
	}

	# Fiche
	handle_path /lettermbox/* {
	   root * /var/www/lettermbox
      	file_server
       	try_files index.txt
	}

	# Git Old
	route /git* {
      	uri strip_prefix /git
       	reverse_proxy localhost:3000
	}

	# Git New (DON'T FORGET TO EDIT THE CGIT CONFIG)
    handle_path /cgit-resource* {
    	root * /usr/share/cgit/
   		file_server
   	}
    handle_path /cgit* {
    	# xcaddy build --with github.com/aksdb/caddy-cgi/v2
    	cgi * /usr/lib/cgit/cgit.cgi
    }
}

3. The problem I’m having:

Firstly, I just today switched from nginx to caddy, and I’m really impressed about it’s simplicity! I had it back up and running with almost no issues in a very short amount of time, where I would have faced many issues with nginx!

While the cgit homepage is now working correctly for the first time with caddy, I still can’ get cgit to detect the repo I clicked on, it always sais the file is not found.

Any idea why that could be? The repo path seems correct.

4 What I already trid

I tried stripping the url prefix “cgit”

Any help would be greatly appreciated!

Please post some logs.
If possible, with the debug global option

Thank you :innocent:

I have already tried looking at the logs, but I couldn’t find anything of interest. I think my main issue here is that I don’t know what to look for and where. Where would errors from that cgi directive end up? In the website log (domain block), or the caddy log (global block)? Anywhere else?

See the docs. Your logs will be in the journal:

FYI, a matcher of / will only match exactly / and nothing else. Probably not what you want.

There’s no reason to set this. That’s already the default. You can remove this.

Why are you turning off admin? That means you can’t reload Caddy at all. The admin API is what’s used for handing Caddy the new config with caddy reload.

You can replace this with handle_path, which has built-in strip_prefix behaviour.

1 Like
  1. Yeah I did. I just can’t remember encountering any cgi logs.
  2. Weird things happen when I use /*. I tried, but it does not do what I want it to.
  3. Oh ok
  4. I just don’t want any security risks caused by an exposed admin api. I restart caddy with systemd anyways.
  5. Oh neat, will do.

Edit: Regarding 2 - this actually brings me to an issue I encountered: Is it possible to provide a fileserver on / and /data without two different blocks? I tried using a named matcher to include both with regex, but It expected a path.

https://chonkyrabbit.eu/lettermbox/tg3r69/

https://chonkyrabbit.eu/lettermbox/hkkmll/

I can’t see any errors in there.

This is my new config. The handle_errors directive is also not working at all. Maybe anyone has an idea about that?

I just managed to fix that cgit issue at least. For whatever reason, my git repository did not contain a .git folder. Apparently I did something wrong a while ago.

I also needed to point it at the repo’s .git folder in the cgitrc

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