1. 程式人生 > >nginx 更改配置client_max_body_size沒有生效 nginx.conf 修改預設限制上傳附件大小

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 {

                }

     }