Caddy File_Server's Files Give 404 Error

1. Caddy version (caddy version):

v2.0.0

2. How I run Caddy:

a. System environment:

Windows 10 1909, Command Prompt

b. Command:

caddy run -adapter caddyfile -config Caddyfile

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

brothermingstream.zapto.org {
    route {
        route /hls/* {
            uri strip_prefix /hls
            file_server {
                root Z:/home/emun/hls/ingress/
            }
        }
        reverse_proxy /* https://localhost:5050 {
            header_down Access-Control-Allow-Origin "*"
            transport http {
                tls_insecure_skip_verify
            }
        }
    }
    log {
        output stdout
    }
}

3. The problem I’m having:

I am trying to do a GET request to /hls/key_720.m3u8. Caddy gives a 404 error. I believe that my Caddyfile may have something wrong with it? I had it briefly working (successfully retrieve /hls/key_720.m3u8) while I was working with localhost. Once I used a DDNS to make my web server publicly available and changed my Caddyfile accordingly, the request started to return 404.

My file_server root is Z:/home/emun/hls/ingress/. I have a Z drive that is network-shared to my WSL Ubuntu18.04 directory. In File Explorer, going to the Z:\home\emun\hls\ingress\ folder, there is a file called key_720.m3u8.

4. Error messages and/or full log output:

Browser console error:
VM102:1 GET https://brothermingstream.zapto.org/hls/key_720.m3u8 404

Caddy log:

2020/05/29 08:04:58.024 e[34mINFOe[0m   using provided configuration    {"config_file": "Caddyfile", "config_adapter": "caddyfile"}
2020/05/29 08:04:58.044 e[34mINFOe[0m   admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["127.0.0.1:2019", "localhost:2019", "[::1]:2019"]}
2020/05/29 08:04:58.048 e[34mINFOe[0m   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}
2020/05/29 08:04:58.048 e[34mINFOe[0m   http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2020/05/29 04:04:58 [INFO][cache:0xc00078c0a0] Started certificate maintenance routine
2020/05/29 08:04:58.060 e[34mINFOe[0m   tls     cleaned up storage units
2020/05/29 08:04:58.065 e[34mINFOe[0m   http    enabling automatic TLS certificate management   {"domains": ["brothermingstream.zapto.org"]}
2020/05/29 08:04:58.092 e[34mINFOe[0m   autosaved config        {"file": "C:\\Users\\Eric Mun\\AppData\\Roaming\\Caddy\\autosave.json"}
2020/05/29 08:04:58.092 e[34mINFOe[0m   serving initial configuration

2020/05/29 08:04:59.073 e[31mERRORe[0m http.log.access.log0 handled request {"request": {"method": "GET", "uri": "/hls/key_720.m3u8", "proto": "HTTP/2.0", "remote_addr": "192.168.1.166:56756", "host": "brothermingstream.zapto.org", "headers": {"User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"], "Sec-Fetch-Site": ["same-origin"], "Sec-Fetch-Dest": ["empty"], "Referer": ["https://brothermingstream.zapto.org/"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": [".AspNetCore.Antiforgery.WgyjVqvh01M=CfDJ8IJc2rAnMqpJumCXhgt0MUk4Nf-cPSuq2t29OJP46yPP1hZtKfTM6HcXkbqvpMQCV1IP_eqWIQiIPZxILYYeUqa3X6DyFMH1xbLLOj6YNZOyu7ns3uS_Eo994M0G5jcuU1u4rZvoC_-eJWBWvkjTkCA; .AspNetCore.Identity.Application=CfDJ8IJc2rAnMqpJumCXhgt0MUnyNzDSQsLahlSOFrZFcqIpucexRfUj1m8BCKFqZtozVu92wopRRpacWaoknYK7cjk02Gah4kRgCLFwHTiartLlGfnouyVLSUlxyJb9FRYqXsSa0BQVEJtvAAlrPPXUvkhkhcvJRylbxTBox_Y7r9GE_-iTNMndvhbR9feozfjsV6Z3dx4CHgey-pl3h5ZFC28zILbzxi_UhO9MiXQk7WwUcgJyJ7YW6Fgd6PyJPBIj460nwCfNQpwx_agDdZo04gssxLn-Kvl-LVaakKLxCF1gD6jeZ6MVnnifo6kGYBJm1z3zF3GvAanT1MU2_TdbBKWRTpcGEhWR-sek-i0oaBj281kKzeHV1VBc-BHZU9cLX4t7fC3Rpcm1GClD9iN_qkhfViKQnSLmuiiCTF24mX7nch_vvQE5DhJfiDA6tJ7kVMOrZ28CbQNPANEDaxK6H0Oid2uaRhdCasgzrtzZCs3l1ZFHB4V3gEvTtloWEtMoPHgtgUABp0XsTaDAcYL43UuPmwAiLUFNnd1g0waWzfk2whiG-rXDBn579p15CmkeNMLYRXaUrkYMdsbzX6hrbmeR8tdPNi7Vpbo-CR7JejdotdL1389t3C1DaW_uMJ5DsVxwqlTZgqCWpDKt80RHeqlGEqqF4knkVtE5n6JxVkADRErtRCOUZPjx3IhWYIpCGEEia5VFiUfz8J19ZjqP08P-w-vJx50lGt0-k7QeVjqzlNQwD4oL6iWu_T-p5vIubxeYsWqJ7mulXTHQQBSFb1LnjKHvoca8tQNUuAmUvZFJpBIWDB3TqtlvhmfeiFJahw"], "Accept": ["*/*"], "Sec-Fetch-Mode": ["cors"]}, "tls": {"resumed": false, "version": 772, "ciphersuite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "brothermingstream.zapto.org"}}, "common_log": "192.168.1.166 - - [29/May/2020:04:07:10 -0400] \"GET /hls/key_720.m3u8 HTTP/2.0\" 404 0", "duration": 0, "size": 0, "status": 404, "resp_headers": {"Server": ["Caddy"]}}

5. What I already tried:

I tried reverting back to my localhost implementation of my webserver, but it did not resolve the issue. I might have not reverted exactly to how the config was when it worked.

The issue may also be due to changes I’ve done with my router settings (port forwarding 80, 443; static ip on my computer) to setup DDNS. I tried reverting those too, but no dice.

6. Links to relevant resources:

So my understanding is that the file you’re trying to serve is at Z:/home/emun/hls/ingress/key_720.m3u8?

Could you try this? I don’t think the first route is necessary, and you can remove /* from the reverse_proxy because that’s the same as just omitting the matcher entirely.

brothermingstream.zapto.org {
    route /hls/* {
        uri strip_prefix /hls
        root Z:/home/emun/hls/ingress/
        file_server
    }
    reverse_proxy https://localhost:5050 {
        header_down Access-Control-Allow-Origin "*"
        transport http {
            tls_insecure_skip_verify
        }
    }
    log {
        output stdout
    }
}

Another thing you could try to debug this - change file_server to file_server browse and make a request to https://brothermingstream.zapto.org/hls/, it should show you a listing of the files at the root. This might reveal the issue.

Yes.

I changed my Caddyfile to

brothermingstream.zapto.org {
    route /hls/* {
        uri strip_prefix /hls
        root Z:/home/emun/hls/ingress/
        file_server browse
    }
    reverse_proxy https://localhost:5050 {
        header_down Access-Control-Allow-Origin "*"
        transport http {
            tls_insecure_skip_verify
        }
    }
    log {
        output stdout
    }
}

When I go to https://brothermingstream.zapto.org/hls/, I get a 404 error:

This brothermingstream.zapto.org page can’t be found No webpage was found for the web address: https://brothermingstream.zapto.org/hls/
HTTP ERROR 404

Caddy output:

2020/05/29 22:40:09.379 e[31mERRORe[0m http.log.access.log0 handled request {"request": {"method": "GET", "uri": "/hls/", "proto": "HTTP/2.0", "remote_addr": "192.168.1.166:57051", "host": "brothermingstream.zapto.org", "headers": {"Sec-Fetch-Dest": ["document"], "Accept-Encoding": ["gzip, deflate, br"], "Cache-Control": ["max-age=0"], "Upgrade-Insecure-Requests": ["1"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-User": ["?1"], "Accept-Language": ["en-US,en;q=0.9"], "Cookie": [".AspNetCore.Antiforgery.WgyjVqvh01M=CfDJ8IJc2rAnMqpJumCXhgt0MUk4Nf-cPSuq2t29OJP46yPP1hZtKfTM6HcXkbqvpMQCV1IP_eqWIQiIPZxILYYeUqa3X6DyFMH1xbLLOj6YNZOyu7ns3uS_Eo994M0G5jcuU1u4rZvoC_-eJWBWvkjTkCA; .AspNetCore.Identity.Application=CfDJ8IJc2rAnMqpJumCXhgt0MUmDR9lY4xRQrTZ73vftL5SOczgMuUNTb6sYE1vf00PHWIC5YJ0mBcwO9RM8G1IjHPwvs3-JJgmrsJfUDqd4h-5qkHL7qs2VmBsjGm9N3APNI4Vxqapwn--IoCpSmMwOKOz8ynDnQpOw3CtYGLzPy6EE1LXktrDc53a658NXjEyU2XsayGNvAb7nTCSLmHm8cEE1kKC-OUy2l6UCaSZ1Cj2oEeMVGqIX_M3nlfCFXzGxM_r9voxteZlT-OBXURJuUptulCQ_44-g-18OKjhgwKEUGx6aNKAVZ1TCap-6sGmBdclPCS5fK2Gex-mxCWuwtrp45iqiAqfYWlZU0s545_3Nyb5SfEkM92btXfqTSdJHDCXso49J8GP2cc5wtIbJN5f0Ptjg377Zxi6gbDFZ5--Y7pv7MDVDO6umNK-l95tIJKIDV33AoohxX7LHpeuGiysUBMpsPQpLZ_o-Y8OyH7Ym7ATMPr9RWpTgJFVrqBol2eSz8FWyj5-PWrGBOYZqbkaeAKBXQ7rCjx64cMokAowj4Ej-PSdcu6pIifeHv6bBsqzSUu-gcS8f24Kd-LAd-sCUtwgBouBjJa-C9-fznDhDzkv3tXLV3AxpAGmf4ThXNRRNcIBlgem5jLYlWzYYk0RsltbtIkr2pFnvIPDyQng0eBJogjnJ43PCJKyXz7QcSq1ygWu7UfMcTh-9IAxcXrjs9nyqKg5Eian2I9VunoPuOSanYqtsP0JZaDKZnFN4RcjsIcLv3RtfIioG7tGXkpTNkLqVimjB8cM9WkA1A2TxuQrOaeJ9fUIaJ9zBzuGXSD6vppqbJLKzI_JjwW3dYqzybbcDNUBCgiZJh5vZU5PjF3ifD3MHRhGm3xkjoTDDtIBbzR-WGV7AQvvQYuLK3KvHFe9T3VqL9gUMQ7dRntvtdjRlA2j63pQxnCM5Fa8MeQ"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"]}, "tls": {"resumed": false, "version": 772, "ciphersuite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "brothermingstream.zapto.org"}}, "common_log": "192.168.1.166 - - [29/May/2020:18:40:09 -0400] \"GET /hls/ HTTP/2.0\" 404 0", "duration": 0, "size": 0, "status": 404, "resp_headers": {"Server": ["Caddy"]}}

I doubt it’s the adapter, but this is the JSON it creates from the Caddyfile:

{
  "apps":{
    "http":{
      "servers":{
        "srv0":{
          "listen":[
            ":443"
          ],
          "logs":{
            "logger_names":{
              "brothermingstream.zapto.org":"log0"
            }
          },
          "routes":[
            {
              "handle":[
                {
                  "handler":"subroute",
                  "routes":[
                    {
                      "handle":[
                        {
                          "handler":"subroute",
                          "routes":[
                            {
                              "handle":[
                                {
                                  "handler":"rewrite",
                                  "strip_path_prefix":"/hls"
                                }
                              ]
                            },
                            {
                              "handle":[
                                {
                                  "handler":"vars",
                                  "root":"Z:/home/emun/hls/ingress/"
                                }
                              ]
                            },
                            {
                              "handle":[
                                {
                                  "browse":{

                                  },
                                  "handler":"file_server",
                                  "hide":[
                                    "Caddyfile"
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ],
                      "match":[
                        {
                          "path":[
                            "/hls/*"
                          ]
                        }
                      ]
                    },
                    {
                      "handle":[
                        {
                          "handler":"reverse_proxy",
                          "headers":{
                            "response":{
                              "set":{
                                "Access-Control-Allow-Origin":[
                                  "*"
                                ]
                              }
                            }
                          },
                          "transport":{
                            "protocol":"http",
                            "tls":{
                              "insecure_skip_verify":true
                            }
                          },
                          "upstreams":[
                            {
                              "dial":"localhost:5050"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "match":[
                {
                  "host":[
                    "brothermingstream.zapto.org"
                  ]
                }
              ],
              "terminal":true
            }
          ]
        }
      }
    }
  },
  "logging":{
    "logs":{
      "default":{
        "exclude":[
          "http.log.access.log0"
        ]
      },
      "log0":{
        "include":[
          "http.log.access.log0"
        ],
        "writer":{
          "output":"stdout"
        }
      }
    }
  }
}

To narrow things down further, can you change your root to some folder on your system that’s not in the Z drive? It might be an issue external to Caddy here. I don’t really see anything wrong with the config.

Looks like my Z drive was the issue. I changed it to C drive and it works. Thank you for the help!

1 Like

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