Unexpected 404 from file_server

1. My Caddy version (caddy version):

I am using caddy/caddy:alpine in docker. So that would be v2.0.0-beta.13 right now.

2. How I run Caddy:

a. System environment:

Digitalocean market place droplet Ubuntu Docker 5:19.03.1~3 on 18.04

c. Service/unit/compose file:

version: '3.7'
services:
  db:
    # specify container name to make it easier to run commands.
    # for example, you could run docker exec -i postgres psql -U postgres postgres < schema.sql to run an SQL file against the Postgres database
    container_name: bb_db
    restart: always
    image: couchdb:latest
    env_file:
      - ./.env
    networks:
      - network
    expose:
      - '5984'
      - '4369'
      - '9100'
    ports:
      - '5984:5984'
    volumes:
      - db_data:/opt/couchdb/data
  caddy:
    build:
      context: ./caddy
    container_name: bb_caddy
    networks:
      - network
    depends_on:
      - db
    restart: always
    # original image downgrades user but that seems not to work
    # see: https://caddy.community/t/basic-docker-compose-setup-failing/6892/7?u=alexander_gabriel
    user: root
    ports:
      - '80:80'
      - '443:443'
    env_file:
      - ./.env
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - caddy_certs:/root/.local/share/caddy
      - caddy_config:/root/.config/caddy
volumes:
  db_data:
  caddy_certs:
  caddy_config:
networks:
  network:

The dockerfile is:

FROM caddy/caddy:alpine
COPY /html /html

d. My complete Caddyfile or JSON config:

{
  email alex.barbalex@gmail.com
}

evab.ch, www.evab.ch {
  root * /html
  encode gzip
  file_server
}

api.evab.ch {
  reverse_proxy * {
    to bb_db:5984
    header_down Access-Control-Allow-Origin *
  }
}

3. The problem I’m having:

curl https://evab.ch returns nothing.

curl -v https://evab.ch returns:

root@pca:/mnt/c/Users/alexa# curl -v https://evab.ch
* Rebuilt URL to: https://evab.ch/
*   Trying 134.209.247.100...
* TCP_NODELAY set
* Connected to evab.ch (134.209.247.100) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Unknown (8):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Client hello (1):
* TLSv1.3 (OUT), TLS Unknown, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=evab.ch
*  start date: Feb 25 10:57:42 2020 GMT
*  expire date: May 25 10:57:42 2020 GMT
*  subjectAltName: host "evab.ch" matched cert's "evab.ch"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* Using Stream ID: 1 (easy handle 0x7fffd27b47e0)
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
> GET / HTTP/2
> Host: evab.ch
> User-Agent: curl/7.58.0
> Accept: */*
>
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* TLSv1.3 (OUT), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
* TLSv1.3 (IN), TLS Unknown, Unknown (23):
< HTTP/2 404
< server: Caddy
< content-length: 0
< date: Fri, 28 Feb 2020 11:29:13 GMT
<
* Connection #0 to host evab.ch left intact

4. Error messages and/or full log output:

docker logs bb_caddy reveals nothing.

5. What I already tried:

1. The db works fine. curl https://api.evab.ch/bb returns:

root@pca:/mnt/c/Users/alexa# curl https://api.evab.ch/bb
{"db_name":"bb","purge_seq":"0-g1AAAAEzeJzLYWBg4MhgTmHgzcvPy09JdcjLz8gvLskBCjPlsQBJhgdA6j8QZCUy4FV3AKLuPiF1CyDq9hNS1wBRNx-3uqQEIJlUj9dtSQ4gNfH41SiA1NjjVZPIkCQPUZAFAN6AYvY","update_seq":"4868-g1AAAAFLeJzLYWBg4MhgTmHgzcvPy09JdcjLz8gvLskBCjMlMiTJ____PysJyNbAoSZJAUgm2cOUteFS5gBSFg9Tlo5LWQJIWT1MWTIOZXksQJKhAUgBVc4HK83Gq3QBROl-sNIIvEoPQJTeByuNw6v0AUQpxK3ZWQBcjWYS","sizes":{"file":4621904,"external":8014600,"active":4570121},"other":{"data_size":8014600},"doc_del_count":0,"doc_count":4868,"disk_size":4621904,"disk_format_version":7,"data_size":4570121,"compact_running":false,"cluster":{"q":8,"n":1,"w":1,"r":1},"instance_start_time":"0"}

2. I have a different project that serves files almost exactly same which works fine:

3. searched docs and this forum

6. Links to relevant resources:

Here is the project: https://github.com/barbalex/bb2/tree/master/docker

What is the complete and unmodified output of ls -la /home?

Also, try file_server browse just to see.

root@bb-docker:~/bb# ls -la /home
total 8
drwxr-xr-x  2 root root 4096 Apr 24  2018 .
drwxr-xr-x 23 root root 4096 Feb 23 18:04 ..

Changing the Caddyfile to:

{
  email alex.barbalex@gmail.com
  #acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}

evab.ch, www.evab.ch {
  root * /html
  encode gzip
  file_server browse
}

api.evab.ch {
  reverse_proxy * {
    to bb_db:5984
    header_down Access-Control-Allow-Origin *
  }
}

made no difference.

Ah, well, that’s why then, right? The site’s root folder is empty. There is no index file, so it returns a 404 because it is not found.

The idea of adding “browse” is so you can see what files are in the folder from Caddy’s perspective, as a sanity check. :slight_smile:

I think you’re showing us the wrong dir.

The site should be in the /html folder.

root@bb-docker:~/bb/caddy/html# docker exec bb_caddy ls /html
404
404.html
6-31cb7bbb5d6fbe7d8bae.js
6-31cb7bbb5d6fbe7d8bae.js.map
app-41c405687795bca2d935.js
app-41c405687795bca2d935.js.map
chunk-map.json
commons-d86be858eccf573e5141.js
commons-d86be858eccf573e5141.js.map
component---node-modules-gatsby-plugin-offline-app-shell-js-498d614abd91358533fa.js
component---node-modules-gatsby-plugin-offline-app-shell-js-498d614abd91358533fa.js.map
component---src-pages-404-js-56374a69555231e5218d.js
component---src-pages-404-js-56374a69555231e5218d.js.map
icons
idb-keyval-iife.min.js
manifest.webmanifest
offline-plugin-app-shell-fallback
page-data
static
styles-a32b059f8609a8ed1598.js
styles-a32b059f8609a8ed1598.js.map
styles.31e2548e15cb1e99e865.css
sw.js
webpack-runtime-7d2f528bacf64ccf849c.js
webpack-runtime-7d2f528bacf64ccf849c.js.map
webpack.stats.json
workbox-v4.3.1

Oh, sorry, you’re right. ls -la /html is what I meant.

hope I got the right command above? (I am not a backend guy)

Here the complete thing:

root@bb-docker:~/bb/caddy/html# docker exec bb_caddy ls -la /html
total 5604
drwxr-xr-x    8 root     root          4096 Feb 27 17:24 .
drwxr-xr-x    1 root     root          4096 Feb 27 17:54 ..
drwxr-xr-x    2 root     root          4096 Feb 27 17:23 404
-rw-r--r--    1 root     root        144857 Feb 27 17:23 404.html
-rw-r--r--    1 root     root        117302 Feb 27 17:23 6-31cb7bbb5d6fbe7d8bae.js
-rw-r--r--    1 root     root        516470 Feb 27 17:23 6-31cb7bbb5d6fbe7d8bae.js.map
-rw-r--r--    1 root     root        834803 Feb 27 17:23 app-41c405687795bca2d935.js
-rw-r--r--    1 root     root       3359378 Feb 27 17:23 app-41c405687795bca2d935.js.map
-rw-r--r--    1 root     root           280 Feb 27 17:23 chunk-map.json
-rw-r--r--    1 root     root        128179 Feb 27 17:23 commons-d86be858eccf573e5141.js
-rw-r--r--    1 root     root        380133 Feb 27 17:23 commons-d86be858eccf573e5141.js.map
-rw-r--r--    1 root     root           499 Feb 27 17:23 component---node-modules-gatsby-plugin-offline-app-shell-js-498d614abd91358533fa.js
-rw-r--r--    1 root     root          1611 Feb 27 17:23 component---node-modules-gatsby-plugin-offline-app-shell-js-498d614abd91358533fa.js.map
-rw-r--r--    1 root     root           297 Feb 27 17:23 component---src-pages-404-js-56374a69555231e5218d.js
-rw-r--r--    1 root     root           297 Feb 27 17:23 component---src-pages-404-js-56374a69555231e5218d.js.map
drwxr-xr-x    2 root     root          4096 Feb 27 17:23 icons
-rw-r--r--    1 root     root          1089 Feb 27 17:23 idb-keyval-iife.min.js
-rw-r--r--    1 root     root          1019 Feb 27 17:23 manifest.webmanifest
drwxr-xr-x    2 root     root          4096 Feb 27 17:23 offline-plugin-app-shell-fallback
drwxr-xr-x    5 root     root          4096 Feb 27 17:23 page-data
drwxr-xr-x    2 root     root          4096 Feb 27 17:23 static
-rw-r--r--    1 root     root           164 Feb 27 17:23 styles-a32b059f8609a8ed1598.js
-rw-r--r--    1 root     root           107 Feb 27 17:23 styles-a32b059f8609a8ed1598.js.map
-rw-r--r--    1 root     root        139249 Feb 27 17:23 styles.31e2548e15cb1e99e865.css
-rw-r--r--    1 root     root          5125 Feb 27 17:23 sw.js
-rw-r--r--    1 root     root          2501 Feb 27 17:23 webpack-runtime-7d2f528bacf64ccf849c.js
-rw-r--r--    1 root     root         12693 Feb 27 17:23 webpack-runtime-7d2f528bacf64ccf849c.js.map
-rw-r--r--    1 root     root          1383 Feb 27 17:23 webpack.stats.json
drwxr-xr-x    2 root     root          4096 Feb 27 17:23 workbox-v4.3.1

Thanks for the update!

So, there’s no index file, so a request to / will return a 404 Not Found because the index file is not found, because it doesn’t exist. If you put an index file in your site root, it will show up.

1 Like

OMG. This is the output from the public folder of a gatsby project. Will have to find out why the index.html is missing.

Sorry for bugging you with unrelated problems and THANKS A LOT for helping!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.