连续发了几天 ByteByteGo 的图片,今天换换口味。

在 Coolify 上部署并使用 GitLab 或 Gitea 时,有时会遇到下面这样的错误。

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v <你的 remote> <本地分支>:<远程分支>
POST git-receive-pack (chunked)
error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly
Pushing to <你的 git url>
Everything up-to-date
Completed with errors, see above.

你上网搜索后,可能会找到一种做法,调整 Git 的分块缓冲区。

1
git config --global http.postBuffer <某个很大的数字>

为什么设置 git config http.postBuffer 没用?

Git 的 http.postBuffer 是什么?

  • 这是 Git 通过 HTTP POST 发送数据时所使用的缓冲区大小。
  • Git 默认把数据分成小块发送,通常为 1 MB。
  • 调大 postBuffer 意味着每块变大,从而减少请求次数。

为什么这次没用?

问题不在于 Git 怎么发送数据,而在于 Coolify 代理的 HTTP 超时,具体过程如下。

  1. Git 仍能把数据发送到 Traefik 代理。
  2. Traefik 代理等待 Git 服务器(GitLab 或 Gitea)响应。
  3. Git 服务器需要时间处理 数据,例如压缩、建立索引和校验。
  4. Traefik 先超时了,Git 服务器还没来得及响应 → HTTP 504。

无论 Git 发送的是大块还是小块,Git 服务器处理数据所需的时间都一样。因此,增大 postBuffer 解决不了代理层的超时。

请求路径与故障原因

git push 的流程

Git Client → Traefik Proxy → Git Server (GitLab/Gitea)
     ↑                ↑              ↑
  postBuffer    readTimeout     Processing time

各个环节

  1. Git 客户端 通过 HTTP POST 发送数据。仓库较大时可能需要几秒。
  2. Traefik 代理 接收请求并转发给 Git 服务器。
  3. Git 服务器 开始处理请求。
    • 解压 Git 对象
    • 检查完整性
    • 更新 refs
    • 运行 Git hook(如果有)
  4. Traefik 在 readTimeout 时限内等待响应(默认约 30 秒)。
  5. Git 服务器处理时间超过这个时限 → Traefik 返回 HTTP 504。

为什么在 Coolify 上会遇到这个问题?

  • Coolify 使用 Traefik 作为反向代理。
  • Traefik 默认的 readTimeout 较短。
  • 针对大文件或大型仓库的 Git 操作通常要处理 30 秒以上。
  • 这个问题不只影响 Git,也影响其他需要较长处理时间的 HTTP 服务。

解决办法

进入 Server > (你的服务器,通常是 localhost) > Proxy > Configuration。

1

把下面两行加到 services.traefik.command 中。

1
2
- '--entrypoints.http.transport.respondingTimeouts.readTimeout=600s'
- '--entrypoints.https.transport.respondingTimeouts.readTimeout=600s'

参数说明

  • readTimeout 是 Traefik 等待从后端读取响应的最长时间。
  • 600s(10 分钟)适用于较大的 git push 操作。
  • 具体数值可以根据仓库大小和网络速度调整。

下面是完整的配置示例。之后的 Coolify 版本可能会有改动,参考这两行的添加方式就好。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: coolify-proxy
networks:
  coolify:
    external: true
services:
  traefik:
    container_name: coolify-proxy
    image: 'traefik:v3.1'
    restart: unless-stopped
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    networks:
      - coolify
    ports:
      - '80:80'
      - '443:443'
      - '443:443/udp'
      - '8080:8080'
    healthcheck:
      test: 'wget -qO- http://localhost:80/ping || exit 1'
      interval: 4s
      timeout: 2s
      retries: 5
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock:ro'
      - '/data/coolify/proxy/:/traefik'
    command:
      - '--ping=true'
      - '--ping.entrypoint=http'
      - '--api.dashboard=true'
      - '--entrypoints.http.address=:80'
      - '--entrypoints.https.address=:443'
      - '--entrypoints.http.http.encodequerysemicolons=true'
      - '--entryPoints.http.http2.maxConcurrentStreams=250'
      - '--entrypoints.https.http.encodequerysemicolons=true'
      - '--entryPoints.https.http2.maxConcurrentStreams=250'
      - '--entrypoints.https.http3'
      - '--providers.file.directory=/traefik/dynamic/'
      - '--providers.file.watch=true'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge=true'
      - '--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=http'
      - '--certificatesresolvers.letsencrypt.acme.storage=/traefik/acme.json'
      - '--api.insecure=false'
      - '--providers.docker=true'
      - '--providers.docker.exposedbydefault=false'
      - '--entrypoints.http.transport.respondingTimeouts.readTimeout=600s'
      - '--entrypoints.https.transport.respondingTimeouts.readTimeout=600s'
    labels:
      - traefik.enable=true
      - traefik.http.routers.traefik.entrypoints=http
      - traefik.http.routers.traefik.service=api@internal
      - traefik.http.services.traefik.loadbalancer.server.port=8080
      - coolify.managed=true
      - coolify.proxy=true

应用更改

  1. 点击 Save,保存 Traefik 配置。
  2. 点击 Restart Proxy,重启代理,让新的超时设置生效。
  3. 检查代理状态。 等代理恢复运行,通常需要 30–60 秒。

注意事项

  • 超时值别设得太高。 真有故障时,连接可能会挂很久。
  • 先用小仓库测试。 确认配置能正常工作。
  • 留意日志。 需要排查问题时,查看 Coolify 和 Traefik 的日志。

祝大家顺利,早点把代码 push 上去!