多容器+Nginx代理环境下,@tus/server结合Uppy上传文件时出现「The file for this url was not found」错误求助
多容器+Nginx代理环境下,@tus/server结合Uppy上传文件时出现「The file for this url was not found」错误求助
大家好,我现在遇到一个tus上传的问题,折腾了好久没搞定,特意来求助!
我后端用的是@tus/server,前端基于React搭配Uppy组件,结果上传文件时一直收到错误提示:
"The file for this url was not found"
我的部署环境是多容器架构,VPS前端还套了Nginx做反向代理。
前端Uppy配置
const [uppy] = useState(() => new Uppy().use(Tus, { endpoint: 'https://app.chatzu.ai/files/' }));
浏览器请求流程
前端发起的请求顺序如下:
Request URL: https://app.chatzu.ai/files Request Method: POST Status Code: 301 Moved Permanently Remote Address: <IP> Referrer Policy: strict-origin-when-cross-origin Request URL: https://app.chatzu.ai/files/ Request Method: GET Status Code: 404 Not Found Remote Address: <IP> Referrer Policy: strict-origin-when-cross-origin
Nginx配置片段
location /files/ { proxy_pass http://172.17.0.4:1080; # Disable request and response buffering proxy_request_buffering off; proxy_buffering off; proxy_http_version 1.1; # Add X-Forwarded-* headers proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; client_max_body_size 0; }
@tus/server后端代码
const { Server } = require('@tus/server'); const { FileStore } = require('@tus/file-store'); const express = require('express'); const host = '0.0.0.0'; const port = 1080; const app = express(); const uploadApp = express(); const server = new Server({ path: '/files', datastore: new FileStore({ directory: '/files' }), }); // Middleware to log all incoming requests uploadApp.use((req, res, next) => { console.log(`[${new Date().toISOString()}] ${req.method} ${req.originalUrl}`); next(); // Pass control to the next middleware or route handler }); uploadApp.all('*', server.handle.bind(server)); app.use('/files', uploadApp); app.listen(port, host, () => { console.log(`Server listening on http://${host}:${port}`); });
麻烦各位大佬帮忙看看问题出在哪,感谢感谢!
备注:内容来源于stack exchange,提问作者Tharusha Jayasooriya




