【问题标题】:nginx client_max_body_size has no effect?nginx client_max_body_size 没有效果?
【发布时间】:2016-05-18 16:09:05
【问题描述】:

我知道这已经被问过好几次了,但我无法让它在我的配置中工作。尝试上传大于默认 nginx 值 client_max_body_size 且大小为 1 MB 的文件时出现 413 错误。

这是我的配置:

nginx.conf:

http {
    client_max_body_size 500M;
    limit_req_status 429;
    limit_conn_status 429;
    limit_req_zone $binary_remote_addr zone=worktoday:40m rate=10r/s;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

mysite.com:

  server {
      client_max_body_size 500M;
      listen 80;

      location / {
          client_max_body_size 500M;

          proxy_pass http://backend;

          proxy_set_header Host $host;

      }

  }

  upstream backend {
      client_max_body_size 500M;
      least_conn;

      server 172.16.10.10;
      server 172.16.10.12;
  }

我尝试了所有组合,将client_max_body_size 放在所有地方(就像现在一样),只在一些地方,将其设置为 0(禁用任何限制)等等。

我很想解决这个问题。

在 nginx 后面有一个使用 gunicorn 运行的烧瓶应用程序。我已经单独尝试了该应用程序(前面没有 nginx)并且它可以工作。

非常感谢您的帮助,谢谢。

【问题讨论】:

  • Nginx 版本?上传失败需要多长时间?检查send_timeout?
  • 它几乎立即失败。我已经尝试过设置send_timeout,但没有任何区别。

标签: nginx flask http-status-code-413


【解决方案1】:

好吧,昨天当我问这个问题时,我完全筋疲力尽,忘记了我们的部署配置。

我们的主服务器充当负载平衡器,后面还有另外两台服务器,它们也有 nginx。我忘记了另外两个 nginx 的存在,而那些是拒绝请求的。

在这两个上设置client_max_body_size终于解决了我的问题。

提示:有时最好先睡一觉再回来解决问题。

【讨论】:

    猜你喜欢
    • 2011-01-04
    • 2018-11-09
    • 2018-02-20
    • 2015-04-13
    • 2016-05-01
    • 2012-02-21
    • 1970-01-01
    • 2017-01-02
    • 2011-06-24
    相关资源
    最近更新 更多