Zoneminder Caddyfile (FreeBSD)

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

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 {             
        php_fastcgi unix//var/run/php-fpm.sock                                       

This works with the FreeBSD Zoneminder pkg. I have not tested any other OS, but this would give you a good start.