nginx v1.22.1
在反向代理 location 段加入
location ^~ /
{
proxy_pass http://127.0.0.1:666;
#强制响应 range 请求,对客户端返回 Accept-Ranges 响应标头及相关 206 状态码
proxy_force_ranges on;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_redirect off;
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 REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# 大文件超时优化
proxy_connect_timeout 86400s;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
send_timeout 86400s;
proxy_buffering off;
client_max_body_size 0;
proxy_request_buffering off;
proxy_socket_keepalive on;
}
这样,在处理文件上传的场景中,就不会因超时、文件太大,缓存太大放入内存等各种意外失败了,全改为边读边发,无缓存。