nginx 更改配置client_max_body_size沒有生效 nginx.conf 修改默認限制上傳附件大小

nginx.conf

在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 路由規則的請求生效。

     http{

#控制全局nginx所有請求報文大小

#client_max_body_size   20m;

                server{

#控制該server的所有請求報文大小

#client_max_body_size   20m;

                        location a {

 

                        }

                        location b{

#控制滿足該路由規則的請求報文大小

#client_max_body_size   20m;

 

                        }

                }

                server {

 

 

                }

     }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章