Issue with fileserver not being found

1. Output of caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

a. System environment:

System is Ubuntu 22.04 LTS
Docker is being used with the official caddy docker image.

b. Command:

docker-compose up -d --build caddy

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane. -->

d. My complete Caddy config:

{ 
    debug
}

example.com {
    reverse_proxy app:5000
}

mail.example.com {
    tls email@domain.tld
    root * /var/www/html
    file_server
}

3. The problem I’m having:

I am trying to host a static html file using Caddy on my subdomain mail.example.com. Issue that I receive is that it shows the following:

root@localhost:~# curl -v mail.example.com
*   Trying ip:80...
* Connected to mail.example.com (ip) port 80 (#0)
> GET / HTTP/1.1
> Host: mail.example.com
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://mail.example.com/
< Server: Caddy
< Date: Wed, 11 Jan 2023 14:25:14 GMT
< Content-Length: 0
< 
* Closing connection 0

4. Error messages and/or full log output:

version: "3"
services:
  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    depends_on:
      - app
    links:
      - app 
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/srv
      - ./data:/data
      - ./config:/confi

5. What I already tried:

I have tried to change around my DNS records to see if it was an issue in there, but didn’t appear to be an issue. I then moved onto looking at the Caddy logs from docker which shows the following:

{"level":"debug","ts":1673447450.0405607,"logger":"http.log.error","msg":"{id=nz45wcygd} fileserver.(*FileServer).notFound (staticfiles.go:579): HTTP 404","request":{"remote_ip":"58.174.118.197","remote_port":"50604","proto":"HTTP/3.0","method":"GET","host":"mail.example.com","uri":"/","headers":{"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Ch-Ua":["\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Brave\";v=\"108\""],"Sec-Ch-Ua-Mobile":["?0"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"],"Accept-Language":["en-GB,en;q=0.9"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-User":["?1"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Upgrade-Insecure-Requests":["1"],"Sec-Gpc":["1"]},"tls":{"resumed":false,"version":0,"cipher_suite":0,"proto":"","server_name":""}},"duration":0.000996067,"status":404,"err_id":"nz45wcygd","err_trace":"fileserver.(*FileServer).notFound (staticfiles.go:579)"}

This is the error that sent me here, as I don’t understand how to fix it. I have the index.html file saved at /var/www/html/index.html so it doesn’t make much sense t ome why it can’t locate that or a fil

6. Links to relevant resources:

That looks normal – you’re making an HTTP request to Caddy, and it’s responding with a redirect (the Location header instructs the client to try again, at a different URL) to HTTPS. Try with curl -v https://mail.example.com instead.

Your Caddyfile config uses /var/www/html as your root, but you didn’t mount that as a volume to your Caddy container.

Containers have no access to files on the host machine. You need to mount them as a volume to give access.

I recommend using /srv instead, as the volume is already set up for you. Move your site’s files to your ./site directory.

1 Like

That fixed it, didn’t realise that the mounted volumes are those the container can access. Well anyways, thank you so much!

2 Likes

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