大网数据广告活动
服务器运维问答

Error uploading large files (>2gb) through nginx reverse proxy to container

· 52CE 我爱测

I am running an application in a docker container ( https://github.com/filebrowser/filebrowser/ ) that I am trying to upload very large (>2) GB files to. The container exposes the app on a nonstandard port on localhost which I co…

问题原文

原帖链接 · BigRed3.14159 · CC BY-SA 4.0

I am running an application in a docker container (https://github.com/filebrowser/filebrowser/) that I am trying to upload very large (>2) GB files to. The container exposes the app on a nonstandard port on localhost which I connect to through a reverse proxy (so I can run multiple apps on one machine). The problem is when I upload a file over 2097152 bytes it errors out. I can see that the files is fully uploaded to nginx and that it partially makes it to the contianerized app but then hangs for a long time at 2097152 bytes before erroring out causing the containerized app to give a unexpected EOF error. I suspect it's something wrong with nginx becuase when I upload a file to the containerized app directly it works fine. I've tried adding a variety of directives to the nginx config and am stumped. My nginx config for the site is:

server {
    server_name example.com;
    client_max_body_size    30g;
    proxy_buffer_size       1024k;
    proxy_buffers 4 1024k;
    proxy_busy_buffers_size 1024k;
    proxy_max_temp_file_size 10000m;
    proxy_connect_timeout   10000;
    proxy_send_timeout      10000;
    proxy_read_timeout      10000;
    send_timeout            10000;
    client_header_timeout   10000;
    client_body_timeout     10000;
    
    location / {
    proxy_pass http://localhost:8088/;
    proxy_http_version 1.1;
    proxy_cache_bypass $http_upgrade;

    proxy_set_header Upgrade           $http_upgrade;
    proxy_set_header Connection        "upgrade";
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;

    proxy_connect_timeout              10000s;
    proxy_send_timeout                 10000s;
    proxy_read_timeout                 10000s;
    }}

The error I get in nginx is:

2022/04/14 20:26:56 [error] 3286524#3286524: *13184 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: example.com, request: "POST /api/resources/Fedora-KDE-Live-x86_64-35-1.2.iso?override=false HTTP/1.1", upstream: "http://[::1]:8088/api/resources/Fedora-KDE-Live-x86_64-35-1.2.iso?override=false", host: "example.com", referrer: "https://example.com/files/" 

Edit: After doing lots of digging, it seems that the solution was to remove the proxy_buffer_size, proxy_buffers, and proxy_busy_buffer_size and add proxy_request_buffering off; I don't know why this works but it does. The modified lines in the config were:

    # proxy_buffer_size       1024k;
    # proxy_buffers 4 1024k;
    # proxy_busy_buffers_size 1024k;
    proxy_request_buffering off;

社区高分解答

原帖链接 · nh2 · CC BY-SA 4.0

Simple answer:


All the other options apply only to downloads to the client (responses). Quoting from the docs:

  • proxy_buffer_size

    ... size of the buffer used for reading the first part of the response received from the proxied server ...

  • proxy_buffers

    ... buffers used for reading a response from the proxied server ...

  • proxy_busy_buffers_size

    ... When buffering of responses from the proxied server ...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。