"nginx + jetty" - post上传body size的限制问题

墨氺 2013-07-17

1 nginx配置修改, 增加红色字体部分 默认1M

 client_max_body_size 0; //表示不限制

 

可以看到content_length大于maxFormContentSize时将抛出异常,而maxFormContentSize默认是200000

 

 

path: /etc/nginx/nginx.conf

 

http {
    include       /etc/nginx/mime.types;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    client_max_body_size 0; //64M
}

 

 

2 jetty配置修改 增加红色部分, 修改最多表单size

org.mortbay.jetty.Request.maxFormContentSize

-1表示不限制,默认200k

 

path: /etc/jetty/jetty.xml 

 

<Call name="addConnector">
      <Arg>
          <New class="org.mortbay.jetty.nio.SelectChannelConnector">
            <Set name="host"><SystemProperty name="jetty.host" /></Set>
            <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
            <Set name="maxIdleTime">30000</Set>
            <Set name="Acceptors">2</Set>
            <Set name="statsOn">false</Set>
            <Set name="confidentialPort">8443</Set>
            <Set name="forwarded">true</Set>
            <Set name="forwardedServerHeader">ignore</Set>
            <Set name="forwardedHostHeader">ignore</Set>
            <Set name="lowResourcesConnections">5000</Set>
            <Set name="lowResourcesMaxIdleTime">5000</Set>
          </New>
      </Arg>
    </Call>


 <Call class="java.lang.System" name="setProperty">
         <Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
         <Arg>-1</Arg>
  </Call>

 

 --------------------

 

tomcat默认允许的content-length=2×1024×1024

// 内容超长则直接返回,jetty会抛出IllegalStateException  

protected void parseParameters() {  
......  
    if (!("application/x-www-form-urlencoded".equals(contentType)))  
        return;  
    int len = getContentLength();   
    if (len > 0) {  
        int maxPostSize = connector.getMaxPostSize();   // tomcat默认大小2*1024*1024    
        if ((maxPostSize > 0) && (len > maxPostSize)) {  
            if (context.getLogger().isDebugEnabled()) {  
                context.getLogger().debug(  
                        sm.getString("coyoteRequest.postTooLarge"));  
            }  
            return;   // 内容超长则直接返回,jetty会抛出IllegalStateException  
            //Parameters 对象没有内容  
    }  
.....  
}

相关推荐