I spent a bit of time working through this, since no one seems to have developed a Caddyfile for Zoneminder. I finally got everything working, including the ZM Ninja app.
First it is necessary to build caddy with the cgi plug-in for caddy v2.
xcaddy build —with github.com/aksdb/caddy-cgi/v2
And here is the Caddyfile.
{
order cgi before respond
}
:80 {
root * /usr/local/www/zoneminder
redir / /zm/ 308
handle_path /zm/cache* {
root * /var/cache/zoneminder
}
handle_path /zm*
handle /api* {
rewrite * /api/app/webroot/index.php?p={path}&{query}
}
cgi /cgi-bin/nph-zms /usr/local/www/zoneminder/cgi-bin/nph-zms {
unbuffered_output
}
php_fastcgi unix//var/run/php-fpm.sock
file_server
}
This works with the FreeBSD Zoneminder pkg. I have not tested any other OS, but this would give you a good start.