Having trouble migrating smokeping Caddyfile to Caddy 2

1. Caddy version (caddy version):

Caddy 2.0.0

2. How I run Caddy:

I run caddy with smokeping and fcgiwrap.

a. System environment:

Debian Buster

b. Command:

0.0.0.0:8981 {
        root * /usr/share/smokeping/www
        php_fastcgi unix//var/run/fcgiwrap.socket {
                env SCRIPT_FILENAME /usr/share/smokeping/smokeping.cgi
        }
}
0.0.0.0:8981/js {
        root * /usr/share/smokeping/www/js
}
0.0.0.0:8981/css {
        root * /usr/share/smokeping/www/css
}
0.0.0.0:8981/cache {
        root * /var/cache/smokeping
}
0.0.0.0:8981/smokeping/images {
              root * /usr/share/smokeping/www/images
}

This is the config I previous used on caddy1, which could be found from here:

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

N/A

3. The problem I’m having:

After I migrated to caddy2, there seems haven’t been a directive like the “http.fastcgi” option in caddy1 (https://caddyserver.com/v1/docs/fastcgi). The document of caddy2 only provide a directive called “php-fastcgi”, which seems only valid for php-fpm. I’ve tried to set the gateway to fcgiwrap.socket and modified the Caddyfile, however, the caddy still return error under the “php_fastcgi” section.

4. Error messages and/or full log output:

run: adapting config using caddyfile: parsing caddyfile tokens for 'php_fastcgi': /etc/caddy/Caddyfile:4 - Error during parsing: unrecognized subdirective env

5. What I already tried:

I’ve tried remove line4, however after remove that line, the webpage turns into blank.
The smokeping and previous Caddyfile(mentioned above, github dot com/caddyserver/examples/blob/master/smokeping/Caddyfile) works well with caddy1.

6. Links to relevant resources:

Thanks in advance.

Hi sparkcyf. I don’t know if it will help or is the right answer but since you’re getting an error “unrecognized sub-directive env” then maybe try using {env.XXX}. It looks like it require a ‘.’ and must be in curly braces.

An example placeholder here

Also check out

There’s a few examples of this placeholder being used on the forum. Do a search for env. and you’ll see how other placed it in their file.

Also if you are trying to server files with those paths you’ll need to enable that in V2

I think you’re actually looking for reverse_proxy with the fastcgi transport if you’re not using PHP.

reverse_proxy unix//var/run/fcgiwrap.socket {
	transport fastcgi {
		env SCRIPT_FILENAME /usr/share/smokeping/smokeping.cgi
	}
}

Also I’d recommend structuring your Caddyfile more like this:

0.0.0.0:8981 {
	handle /js/* {
		root * /usr/share/smokeping/www/js
	}
	handle /css/* {
		root * /usr/share/smokeping/www/css
	}
	handle /cache/* {
		root * /usr/share/smokeping
	}
	handle /smokeping/images/* {
		root * /usr/share/smokeping/www/images
	}
	handle {
		root * /usr/share/smokeping/www
		reverse_proxy unix//var/run/fcgiwrap.socket {
			transport fastcgi {
				env SCRIPT_FILENAME /usr/share/smokeping/smokeping.cgi
			}
		}
	}

	file_server
}

Hi! Thanks for your help. I’ve tried to use the Caddyfile structure that you recommend. However, the situation doesn’t change much. I still get a blank page when I request the page. :man_facepalming:

the log indicates:

 caddy[1515429]: {
   "level": "info",
   "ts": 1591950735.9048076,
   "logger": "http.log.access",
   "msg": "handled request",
   "request": {
     "method": "GET",
     "uri": "/smokeping.cgi?target=_charts",
     "proto": "HTTP/1.1",
     "remote_addr": "*.*.*.*:52117",
     "host": "*.*.*.*:8981",
     "headers": {
       "Accept-Encoding": ["gzip, deflate"],
       "Accept-Language": ["*"],
       "Connection": ["keep-alive"],
       "Dnt": ["1"],
       "Upgrade-Insecure-Requests": ["1"],
       "User-Agent": ["*"],
       "Accept": ["*"]
     }
   },
   "common_log": "*.*.*.* - - [12/Jun/2020:16:32:15 +0800] \"GET /smokeping.cgi?target=_charts HTTP/1.1\" 0 0",
   "duration": 0.000006636,
   "size": 0,
   "status": 0,
   "resp_headers": {
     "Server": ["Caddy"]
   }
 }

When I serve smokeping with caddy1, the successful request returns:

2020/06/12 15:58:56 *.*.*.* - - [12/Jun/2020:15:58:56 +0800] "GET /smokeping.cgi?target=_charts HTTP/1.1" 200 4088

and there is no file under /usr/share/smokeping/www/images (The smokeping will generate some image cache of the graph once it has been accessed successfully).

I’ve also tried to get the static file of the smokeping (like its css at /css/smokeping-print.css) but it returns a blank page with the log quite same as the error log above, too.

It may seems like the caddy haven’t transfer the request to the fcgiwrap? (I’m sure the fcgiwrap is running normally and works well with caddy1)

Any advise on this issue or advise on debugging is greatly appreciated.

Could you add this to the top of your Caddyfile and try again and check the logs?

{
	debug
}

It should reveal some more info about what’s going on.

Aha - someone just posted a bug report having to do with the split functionality of the fastcgi transport.

Could you try this?

reverse_proxy unix//var/run/fcgiwrap.socket {
	transport fastcgi {
		env SCRIPT_FILENAME /usr/share/smokeping/smokeping.cgi
		split ""
	}
}

See the bug report here:

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