上传大文件时 Nginx 代理超时

tom*_*kup 4 nginx timeout upload

我在使用 Nginx 时遇到了奇怪的行为。就我而言,Nginx 充当 Jetty 的代理。配置如下:

server {
    listen   80;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    client_max_body_size 5M;
    server_name test.com www.test.com
    location / {
         auth_basic     "Restricted area";
         auth_basic_user_file   /etc/nginx/htpasswd;
         proxy_pass        http://localhost:8080;
         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 http;
         proxy_set_header  X-Real-IP $remote_addr;
         proxy_set_header  Host $http_host;
         gzip on;
    }
}
Run Code Online (Sandbox Code Playgroud)

上传大小大于 5M 的文件时,出现“网关超时”。CPU 使用率为 0%。我不知道出了什么问题。它与网络速度无关,因为我正在本地测试。

如果我跳过代理并尝试直接将文件上传到应用程序服务器(我的意思是:在端口 8080 上),一切都像魅力一样。

任何的想法 ??问候!

小智 6

可能需要增加 nginx 上游超时。尝试将以下添加到您的上游 conf。

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;
Run Code Online (Sandbox Code Playgroud)


Far*_*han 1

可能您需要更改限制

 client_max_body_size 5M;
Run Code Online (Sandbox Code Playgroud)

类似的东西

 client_max_body_size 10M;
Run Code Online (Sandbox Code Playgroud)