You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Supabase+Kong+TUS断点续传请求地址异常问题求助

解决Supabase + Kong + TUS断点续传URL异常问题

问题核心

初始请求https://myhost.com/storage/v1/upload/resumable能正常通过Kong路由,但TUS后续分片请求会变成https://myhost.com:8000/upload/resumable/<token>,原因是Supabase Storage返回的TUS Location响应头使用了内部服务的端口和原始路径,没有适配Kong的路由规则。

解决方案

1. 配置Kong修正响应头(推荐服务端解决)

给Supabase Storage对应的Kong路由添加response-transformer插件,重写Location头,替换内部地址为外部合法URL:

  • 进入Kong管理界面或通过CLI,找到指向Supabase Storage的路由(路径匹配/storage/v1/*的那条)
  • 添加response-transformer插件,设置:
    • replace.headers.Location规则:将http://localhost:8000/upload/resumable/替换为https://myhost.com/storage/v1/upload/resumable/
    • 或用正则匹配替换:^http://[^:]+:8000/upload/resumable/(.*) → https://myhost.com/storage/v1/upload/resumable/$1

2. 修正Supabase Storage的环境变量

在Coolify的Supabase docker-compose配置中,给storage服务添加以下环境变量,让它生成正确的外部URL:

services:
  storage:
    environment:
      - SITE_URL=https://myhost.com/storage/v1
      - TRUST_PROXY=true
      - FORCE_SSL=true

这些变量会让Storage服务识别反向代理的外部地址,返回的Location头直接使用正确的域名和路径,无需Kong额外修改。

3. 客户端临时适配(备选)

如果服务端配置暂时无法调整,可以在Uppy的TUS插件中添加onBeforeRequest钩子,手动修正请求URL:

.use(Tus, {
  // 原有配置...
  onBeforeRequest: (req) => {
    const url = new URL(req.url);
    // 替换端口和补全路径前缀
    if (url.port === '8000') {
      url.port = '';
      url.pathname = `/storage/v1${url.pathname}`;
      req.url = url.toString();
    }
    return req;
  },
});

内容的提问来源于stack exchange,提问作者ツNoaツ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 06:36:03