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

AlmaLinux 8上Nginx 1.14.1无法正常提供1GB以上私有文件下载

问题描述

在AlmaLinux 8服务器上部署了Nginx 1.14.1,提供私有文件下载服务:

  • 文件小于1GB时下载正常;
  • 下载2GB文件时,Chrome开发者工具显示已完成2GB下载,但最终保存的文件仅4字节;
  • Nginx日志无任何错误记录,浏览器及开发者工具未出现超时或其他报错;
  • 切换Firefox测试,问题复现;
  • 已尝试开启/关闭sendfile,结果一致。

相关Nginx配置片段:

location /protected_pdf/ {
    internal;
    alias   /u01/rp/reports/pdfreports/;
    sendfile off;
    sendfile_max_chunk 5m;
    proxy_max_temp_file_size 0;
    proxy_request_buffering off;
    client_max_body_size 0;
    proxy_buffering off;
}
排查与解决方案

1. 调整Nginx缓冲区配置

Nginx默认缓冲区可能导致大文件传输时数据截断,添加以下配置到location /protected_pdf/块中:

output_buffers 1 64k;
postpone_output 0;

output_buffers设置为小尺寸缓冲区,postpone_output禁用延迟输出,确保数据实时发送到客户端。

2. 验证源文件与文件系统

  • 检查服务器上的源文件完整性:执行ls -lh /u01/rp/reports/pdfreports/[目标文件名]确认文件大小,再用md5sum [目标文件名]校验文件是否损坏;
  • 确认存储文件的文件系统支持大文件:用df -T查看文件系统类型,AlmaLinux 8默认XFS支持大文件,若为ext3需确认是否开启large_file选项。

3. 延长Nginx超时时间

长连接可能因超时被静默中断,在http块或目标location内添加:

send_timeout 300s;
client_body_timeout 300s;

4. 调整TCP参数(针对sendfile关闭场景)

当sendfile关闭时,修改TCP参数避免数据堆积:

location /protected_pdf/ {
    # 保留原有配置
    tcp_nopush off;
    tcp_nodelay on;
}

5. 检查服务器网络限制

  • 确认内核网络缓冲区足够大:执行sysctl net.core.wmem_max net.core.rmem_max,若值小于16MB,临时调整:
sysctl -w net.core.wmem_max=16777216
sysctl -w net.core.rmem_max=16777216
  • 临时关闭firewalld/iptables测试,排除防火墙对长连接或数据量的限制。

6. 升级Nginx版本

Nginx 1.14.1为2019年发布的旧版本,可能存在大文件传输的已知bug,建议升级到最新稳定版(如1.24.x),可通过AlmaLinux的EPEL源或Nginx官方源完成升级。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 18:04:59