Please be more specific. Run caddy version to see the version.
Well, you need to use a request matcher to decide how to handle requests. You probably need to use a request matcher with handle directives to isolate those two chunks of config from eachother.
It’s not clear from what you’ve posted how requests to your server will look, so I can’t help you with that without more information.
No. You need to think about what requests should reach what path.
When I say requests, I mean: what aspect of the request itself tells you whether it should be handled as CGI or handled as a static file?
What URI do your requests look like? For those, which should be run as CGI, and which are just regular files?
The root directive defines which filesystem path Caddy should look for files to serve or proxy via fastcgi. That’s separate from request matching, because your requests won’t have the path /var/www/cgi in them.
It would be better if you put all your files in one place instead of two. Having the roots split up only complicates things.
If you put them in the same place, then all you’d need is a matcher like this to only handle *.cgi files via the fastcgi proxy (the rest will fall through to file_server).