drawio 是一个开源的 画图 webapp

但是支持的文件存储方式,只有 github、谷歌云盘、onedrive 之类的国外网盘

对于自托管没有很好的支持(不能支持自定义个人网盘,比如 webdav)

为此,研究了一套能够自托管的 drawio 部署方式

架构及成果展示

DHk0lg6PzqGu3tzbA80qnaiTICfMDcuX.png

自建的 edit.html

https://gist.github.com/zouzonghao/1c5022f973a791f25a041de8c8aa7793

完整步骤

  1. https://github.com/sigoden/dufs/releases/tag/v0.46.0 下载 dufs ( 一般的 vps 下载 dufs-v0.46.0-x86_64-unknown-linux-musl.tar.gz)解压到 /opt/dufs/dufs
  2. 创建 /opt/dufs/config.yaml 配置文件
    bind:
      - 127.0.0.1
    port: 37002
    # 这里的账号密码,是webdav的账号密码,`@/`是将vps的根目录作为dufs文件服务器的根目录,不推荐,有风险 
    auth:
      - admin:passwd@/:rw  
    allow-all: true
    allow-archive: true
    compress: none
    
  3. debain 创建 dufs 服务 /etc/systemd/system/dufs.service
    [Unit]
    Description=Dufs File Server
    After=network.target local-fs.target
    Wants=network-online.target
    [Service]
    Type=simple
    User=root
    Group=root
    WorkingDirectory=/opt/dufs
    ExecStart=/opt/dufs/dufs / -c /opt/dufs/config.yaml
    Restart=on-failure
    RestartSec=5s
    StandardOutput=append:/var/log/dufs.log
    StandardError=append:/var/log/dufs.err
    PIDFile=/var/run/dufs.pid
    KillMode=process
    KillSignal=SIGTERM
    [Install]
    WantedBy=multi-user.target
    
  4. 启动服务
    # 重新加载 systemd 配置
    sudo systemctl daemon-reload
    # 启动服务
    sudo systemctl enable dufs
    sudo systemctl start dufs
    # 查看状态
    sudo systemctl status dufs
    # 查看日志
    sudo journalctl -u dufs -f
    
  5. 下载 drawio 的源码中的 src/main/webapp 文件夹到 /opt/drawio/webapp
  6. 创建 /opt/drawio/webapp/edit.html 内容为 https://gist.github.com/zouzonghao/1c5022f973a791f25a041de8c8aa7793
  7. 下载安装 caddy,修改/etc/caddy/Caddyfile
    注意将drawio.cn修改为你自己的域名
    drawio.cn:443 {
        encode zstd gzip    
        route {
            handle_path /dav/* {
                reverse_proxy localhost:37002
            }
            root * /opt/drawio/webapp
            file_server
            try_files {path} /index.html
        }
    }
    
  8. 重启 caddy systemctl restart caddy
  9. 访问 你的域名 drawio.cn/edit.html,右下角有一个设置悬浮按钮,点击进入webdav设置,如果你和我一样将根目录/挂载到 dufs 上,那么/dav/,就是对应 vps 的根目录。