当我对特定目录进行 root 时,Caddy 文件服务器浏览不起作用

Caddy file server browse not working when I root a specific directory

这是我的 Caddyfile:

aruiplex.com {
        encode gzip
        file_server /files/* {
                root /files
                browse
        }
        reverse_proxy /api/* localhost:7022
        file_server {
                root /srv
        }
}

这是我的计划:

  1. 当请求URL为aruiplex.com时,Caddy可以显示/srv目录下的index.html

  2. 当请求URL为aruiplex.com/files时,Caddy可以显示docker容器中/files目录下的文件列表。

  3. 当请求URL为aruiplex.com/api时,Caddy可以将此请求传递给localhost:7022.

但是当我请求 aruiplex.com/files 文件服务器不工作时,它给了我一个 404。我检查了 docker 容器中的这个目录,那里有一些文件。

这是我在 docker 容器中 / 的文件树:

/
    /home
    /etc
    /...
    /files
        /aaa.txt
        /bbb.txt
    /srv
        /index.html

版本:Docker.

中的 Caddy 2.4.6

P.S.: 如果你在caddy.community上看到post,那也是我。

部署和服务项目的不同内容

使用 handlehandle_path 指令为网站 API 和文件夹内容提供服务

这是我为同一个用户案例创建的示例项目

├── Caddyfile
├── app
│   └── index.html
├── docker-compose.yml
├── files
│   ├── bye.txt
│   └── hello.txt
└── logs
    └── access.log

Caddyfile,将 8080 替换为您的域 example.com

:8080 {
    handle /api* {
        reverse_proxy localhost:7022
    }
    handle_path /files* {
        root * /files
        file_server browse
    }
    handle {
        root * /srv
        file_server browse
    }
}

:7022 {
    respond "Hey! I AM API" 
}

docker-compose.yml

version: "3"
services:
  caddy:
    restart: always
    image: caddy:2.4.6
    container_name: caddy
    ports:
      - 8080:8080 # Configure Caddyfile with port opened
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
      - ./app:/srv
      - ./files:/files
      - ./logs:/var/log
volumes:
  caddy_data: 
  caddy_config: