Reroute subdomain to separate directory

Hi there :wave:

I am trying to get my Caddyfile to handle my domain in such a way that the root displays a static html file, and the subdomain shows .txt files.

I have gotten to serve these .txt files successfully using caddy file-server --root ~/DBAM/api/ --domain as a standalone command. (example txt)

My issue is, when I try to replicate this in a Caddyfile so that i can have the subdomain api. point to the directory with the txt files, and the root domain point to the /www directory, I am just met with 404 errors when requesting anything (even with the same file path as shown in example txt)

here is my Caddyfile as is; {
        root * /DBAM/www
        file_server {
                index index.html
} {
        root * /DBAM/api

Logged output on caddy start

root@ubuntu-20:~/DBAM# caddy start
2021/08/08 13:25:34.714 INFO    using adjacent Caddyfile
2021/08/08 13:25:34.716 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2021/08/08 13:25:34.719 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", ""]}
2021/08/08 13:25:34.720 INFO    http    server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv0", "https_port": 443}
2021/08/08 13:25:34.721 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2021/08/08 13:25:34.722 INFO    http    enabling automatic TLS certificate management   {"domains": ["", ""]}
2021/08/08 13:25:34.731 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0005f2e70"}
2021/08/08 13:25:34.731 INFO    tls     cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
2021/08/08 13:25:34.734 INFO    tls     finished cleaning storage units
2021/08/08 13:25:34.739 INFO    autosaved config (load with --resume flag)      {"file": "/root/.config/caddy/autosave.json"}
2021/08/08 13:25:34.740 INFO    serving initial configuration
Successfully started Caddy (pid=834968) - Caddy is running in the background

Help with structuring my Caddyfile to achieve the desired outcome would be greatly appreciated <3

What requests are you making exactly (what’s the URL of a request to a file that fails?)

What’s the full path to that file on disk?

For next time, please fill out the help topic template (it appears when you try to open a new topic in the help category).

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