分类: Linux
Nginx解决超长请求串(413 request Entity too Large错误解决办法)

nginx作为反向代理服务器,小文件上传可以,大文件上传会报413,400,414(如 413 request Entity too Large)等状态码,这是因为请求长度超过了nginx默认的缓存大小和最大客户端最大请求大小,增加或修改以下参数,一般可解决此类问题:
http段:

    keepalive_timeout 300;
    proxy_read_timeout 300;
    add_header Access-Control-Allow-Origin *;
    client_max_body_size    1000m;
    client_header_buffer_size 100m;
    large_client_header_buffers 4 512k;

nginx目录下的*temp要有写入权限,请求超出缓冲区大小时会写缓存文件;
location段:

      location ~* ^/OCC_DataCollection_Web/.*$ {
           include deny.conf;

           proxy_pass http://clcapp7300;
           proxy_set_header Host $http_host;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "upgrade";
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Scheme $scheme;
           proxy_set_header X-Script-Name /octoprint;
           client_max_body_size    1000m;

           error_log  logs/clc_OCC_DataCollection_Web_error.log error;
           access_log  logs/clc_OCC_DataCollection_Web_access.log  main;
       }

upstream段:

    upstream clcapp7300 {
      ip_hash;
      server 10.254.0.21:7300 weight=1 max_fails=2 fail_timeout=300s;
      server 10.254.0.22:7300 weight=1 max_fails=2 fail_timeout=300s;
    }


相关博文:

发表新评论