nginx上传client_max_body_size问题 [英] nginx upload client_max_body_size issue

查看:1385
本文介绍了nginx上传client_max_body_size问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行nginx / ruby​​-on-rails,并且有一个简单的multipart表单来上传文件。
一切工作正常,直到我决定限制我想上传的文件的最大大小。
为此,我将nginx client_max_body_size 设置为 1m (请求实体太大)的状态作为回应时,该规则中断。

问题是,当我上传一个1.2 MB的文件,而不是显示HTTP 413错误页面,浏览器挂起一点,然后死亡,连接被重置,而页面正在加载消息。



我试过了每个选项都有nginx提供的,似乎没有任何工作。有没有人有任何想法呢?



这是我的nginx.conf:

  worker_processes 1; 
timer_resolution 1000ms;
事件{
worker_connections 1024;
}

http {
passenger_root / the_passenger_root;
passenger_ruby / the_ruby;

包含mime.types;
default_type application / octet-stream;

sendfile on;
keepalive_timeout 65;

服务器{
听80;
server_name www.x.com;
client_max_body_size 1M;
passenger_use_global_queue on;
root / the_root;
passenger_enabled;

error_page 404 /404.html;
error_page 413 /413.html;




谢谢。 p>




**编辑**



Environment / UA:Windows XP / Firefox 3.6.13

解决方案

当客户端通过发送一个413响应并关闭连接来通知它将发送一个大于 client_max_body_size 的主体时,nginx快速失败。


$ b

大多数客户端在发送整个请求主体之前不会读取响应。因为nginx关闭连接,客户端发送数据到关闭的套接字,导致一个TCP RST。

如果您的HTTP客户端支持它,处理这个的最好方法是发送期望值:100 - 继续标题。 Nginx从1.2.7开始正确支持这个功能,并且会以 413请求实体太大响应而不是 100继续 > if Content-Length 超过最大的身材尺寸。


I'm running nginx/ruby-on-rails and I have a simple multipart form to upload files. Everything works fine until I decide to restrict the maximum size of files I want uploaded. To do that, I set the nginx client_max_body_size to 1m (1MB) and expect a HTTP 413 (Request Entity Too Large) status in response when that rule breaks.

The problem is that when I upload a 1.2 MB file, instead of displaying the HTTP 413 error page, the browser hangs a bit and then dies with a "Connection was reset while the page was loading" message.

I've tried just about every option there is that nginx offers, nothing seems to work. Does anyone have any ideas about this?

Here's my nginx.conf:

worker_processes  1;
timer_resolution  1000ms;
events {
    worker_connections  1024;
}

http {
    passenger_root /the_passenger_root;
    passenger_ruby /the_ruby;

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

    sendfile           on;
    keepalive_timeout  65;

    server {
      listen 80;
      server_name www.x.com;
      client_max_body_size 1M;
      passenger_use_global_queue on;
      root /the_root;
      passenger_enabled on;

      error_page 404 /404.html;
      error_page 413 /413.html;    
    }    
}

Thanks.


**Edit**

Environment/UA: Windows XP/Firefox 3.6.13

解决方案

nginx "fails fast" when the client informs it that it's going to send a body larger than the client_max_body_size by sending a 413 response and closing the connection.

Most clients don't read responses until the entire request body is sent. Because nginx closes the connection, the client sends data to the closed socket, causing a TCP RST.

If your HTTP client supports it, the best way to handle this is to send an Expect: 100-Continue header. Nginx supports this correctly as of 1.2.7, and will reply with a 413 Request Entity Too Large response rather than 100 Continue if Content-Length exceeds the maximum body size.

这篇关于nginx上传client_max_body_size问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆