Caddyfile and v2

Hi,

As commented on another topic, I’m new to Caddy and I’m currently trying v2 beta12 with Caddyfile.

So I’m stuck with a site config, where I want my root path to file_serve to some directory and another path to point to other subdirectories.

I could ask here and probably get a response, but what do you think it’s the best way to learn about how to do it? Having in mind the wiki states:

The new site does not yet have v2 Caddyfile documentation, as the v2 Caddyfile is rapidly changing in preparation for a stable release. The Caddyfile will probably be the last thing to be finalized before the release candidates.

Thanks

Hey @gonzaloserrano, good question.

Try this:

root /path1 /site1
root /path2 /site2

Or if your folders are named after the site: root * /www/{host} will do.

Trying this without luck:

gon.cat {
    root /talks/* /var/www/talks
    root * /var/www/home
    file_server
}

Thanks!

Tried this also without luck:

gon.cat {
    file_server /talks/* {
        root /var/www/talks
    }
    file_server {
        root /var/www/home
    }
}

Also

gon.cat {
    root * /var/www/home
    file_server
    file_server /talks/* {
        root /var/www/talks
    }
}

and

gon.cat {
    root * /var/www/home
    file_server
    file_server /talks {
        root /var/www/talks
    }
}

I can access to the home at root but not to the talks.

If do you think there is a better way to learn about how to do it let me know, thanks.

Also tried this:

gon.cat {
    file_server
    root /talks /var/www/talks
    root / /var/www/home
}

and

gon.cat {
    file_server
    root /talks/vim /var/www/talks/vim
    root / /var/www/home
}

Also changing the order. I’m in beta12 so I don’t have the Caddyfile latest changes.

What do you mean by “without luck”? It’s working for me. You’ll need to be more specific.

Try caddy adapt on your Caddyfile to see what the JSON output is, that may lend a clue.

You are right, sorry for my lack of details.

So, I got this:

gon.cat {
    root /talks/* /var/www/talks
    root * /var/www/home
    file_server
}

Which in JSON is:

{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":443"
          ],
          "routes": [
            {
              "match": [
                {
                  "host": [
                    "gon.cat"
                  ]
                }
              ],
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "handler": "vars",
                          "root": "/var/www/talks"
                        }
                      ],
                      "match": [
                        {
                          "path": [
                            "/talks/*"
                          ]
                        }
                      ]
                    },
                    {
                      "handle": [
                        {
                          "handler": "vars",
                          "root": "/var/www/home"
                        },
                        {
                          "handler": "subroute",
                          "routes": [
                            {
                              "handle": [
                                {
                                  "handler": "file_server",
                                  "hide": [
                                    "Caddyfile"
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
  }
}

My /var/www contains the directories home/ and talks/vim, both beeing static sites.

Results:

Thanks again.