nginx.conf更改配置client_max_body_size 没有生效?????????

在nginx使用过程中,上传文件的过程中,通常需要设置nginx报文大小限制。避免出现413 Request Entity Too Large。

于是奇葩的问题被我们遇到了,详细配置请参考下面。我们的问题是,无论client_max_body_size设置在哪里,nginx -s reload后,依然一直报413.多次尝试reload,始终无效。最终决定kill 进程,restart,终于好了。

 

由此可见,nginx reload并不一定好使。有时候,为了保险起见。restart比较靠谱。

不知道别人有没有遇到同样的问题。希望对大家有帮助!~~(太他吗有帮助了~!!!!!!!!!!!!!)

 

设置如下:

 

Syntax: client_max_body_size size;
Default:
client_max_body_size 1m;
Context: httpserverlocation

 

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field.

If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.

Please be aware that browsers cannot correctly display this error.

Setting size to 0 disables checking of client request body size.

可以选择在http{ }中设置:client_max_body_size   20m;

也可以选择在server{ }中设置:client_max_body_size   20m;

还可以选择在location{ }中设置:client_max_body_size   20m;

三者到区别是:http{} 中控制着所有nginx收到的请求。而报文大小限制设置在server{}中,则控制该server收到的请求报文大小,同理,如果配置在location中,则报文大小限制,只对匹配了location 路由规则的请求生效。

 

Server端tomcat设置:

<Connector  URIEncoding="UTF-8" port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000" maxPostSize="0" ---> 解决tomcat上传文件限制问题
               redirectPort="8443" maxHttpHeaderSize="3145728"/>

  

posted @ 2017-09-26 16:34  iFindU_San  阅读(3027)  评论(0)    收藏  举报