用rclone和cloudflared部署webDAV

webdav 定义

WebDAV协议为用户在服务器上创建、更改和移动文档提供了一个框架。WebDAV协议最重要的功能包括维护作者或修改日期的属性、名字空间管理、集合和覆盖保护。维护属性包括创建、删除和查询文件信息等。名字空间管理处理在服务器名称空间内复制和移动网页的能力。集合(Collections)处理各种资源的创建、删除和列举。覆盖保护处理与锁定文件相关的方面。

部署方式

  1. 新建一个docker-compose.yml文件,记得替换username和password两个变量:
version: '3'
services:
  rclone-webdav-server:
    container_name: rclone-webdav-server
    image: rclone/rclone
    command:
  # Tweak here rclone's command line switches:
  #    - "--config"
  #    - "/path/to/mounted/rclone.conf"
      - "--verbose"
      - "serve"
      - "webdav"
      - "/data"
      - "--user"
      - "${username}"
      - "--pass"
      - "${password}"
      # - "remote:/"
      - "--addr"
      - "0.0.0.0:8080"
      # - "--read-only"
  #    - "--no-modtime"
  #    - "--no-checksum"

    restart: unless-stopped

    # Use host networking for simplicity.
    # It also enables server's default listen on 127.0.0.1 to work safely.
    # net: host

    # If you want to use port mapping instead of host networking,
    # make sure to make rclone listen on 0.0.0.0.
    ports:
     - "0.0.0.0:8085:8080"

    # Here you have to map your host's rclone.conf directory to
    # container's /root/.config/rclone/ dir (R/O).
    # If you have any remote referencing local files, you have to
    # map them here, too.
    volumes:
      - ./config/:/root/.config/rclone/:ro
      - ./data/:/data
  1. 执行docker-compose up -d启动rclone服务
  2. 注册一个cloudflare账号,进入choudflare的控制面板,并注册一个现有域名或者在cloudflare买一个域名
  3. 点击进入zero trust
  4. 点击Access->Tunnels,然后新建一个tunnel如果没有的话
  5. 点击进入编辑tunnel,复制tunnel的token,
  6. 执行如下命令
    docker run -d --restart=always --name=cloudflared cloudflare/cloudflared:latest tunnel --no-autoupdate run --token ${token}
  7. 进入tunnel的public hostname,添加你自己的子域名,在更多配置里面把Disable Chunked Encoding设置为开启
  8. 保存
  9. 浏览器打开你配置的域名看看是否已经可以浏览文件目录
  10. 用webDAV客户端连接看看是否可以连接上