当我 root 特定目录时,Caddy 文件服务器浏览不工作

发布于 2025-01-13 07:02:40 字数 1100 浏览 4 评论 0原文

这是我的 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 可以向我显示 index.html/srv 目录中。

  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。

PS:如果您在 caddy.community 上看到该帖子,也是我。

Here is my Caddyfile:

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

Here is my plan:

  1. When request URL is aruiplex.com, Caddy can show me the index.html in /srv directory.

  2. When request URL is aruiplex.com/files, Caddy can show me the file list in the /files directory in docker container.

  3. When request URL is aruiplex.com/api, Caddy can pass this request to localhost:7022.

But when I request aruiplex.com/files file server is not working, it gives me a 404. And I have check this directory in docker container, there have some files.

Here is my file tree at / in docker container:

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

Version: Caddy 2.4.6 in Docker.

P.S.: If you see the post on the caddy.community, it also me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2025-01-20 07:02:40

部署并提供项目的不同内容

使用要提供服务的 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:

Deploying and serving different contents of the project

Serve the website, API, and content of the folder with the handle and handle_path directives to serve

Here is the sample project I created for the same usercase

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

Caddyfile, replace 8080 with your domain 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文