How to make Caddy2 work with smokeping?

1. Caddy version (caddy version):


2. How I run Caddy:

I use CaddyFile

a. System environment:

ubuntu 20.04

b. Command:

systemctl start caddy

d. My complete Caddyfile or JSON config: {
        log {
                output file /var/log/caddy.log
        handle /js/* {
                root * /usr/share/smokeping/www/js
        handle /css/* {
                root * /usr/share/smokeping/www/css
        handle /cache/* {
                root * /var/cache/smokeping
        handle /images/* {
                root * /usr/share/smokeping/www/images
        handle {
                root * /usr/share/smokeping/www
                reverse_proxy unix//var/run/fcgiwrap.socket {
                        transport fastcgi {
                                split ""
                                env SCRIPT_FILENAME /usr/share/smokeping/smokeping.cgi

3. The problem I’m having:

Now I can access the smokeping webpage. But all js, css, image resources are 404 Not Found. I’m sure the path in the caddyfile is correct. What did I do wrong?

4. Error messages and/or full log output:

404 Not Found.

Please fill out the help topic template. It’s difficult to help without it being properly filled with all the information we require.

Also, make sure to use code blocks in your post when posting your config. It’s very difficult to read your config without indentation preserved.

The way Caddy’s file_server works is by concatenating the defined root with the request’s path.

So for example, the request for /js/foo.js would get handled by your handle /js/* which sets the root to /usr/share/smokeping/www/js, so the file_server handler will look for a file at /usr/share/smokeping/www/js/js/foo.js. You can see that /js/js is doubled up.

The solution is to instead use handle_path, which will strip the matched path prefix from the request before handling the request. This’ll avoid the duplication.

Also, your last handle doesn’t quite make sense. You can’t both reverse_proxy and file_server at the same time, only one will run. In this case, only the reverse_proxy will run because it comes first in the directive order.

Thanks. Now everything works perfectly fine.

1 Like

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