Nginx 错误: client intended to send too large body


有一台原本使用 Apache 的 Web Server 换成 Nginx 后, 其中一个 PHP 的上传档案程式遇到错误, 原本以为是 PHP 的 max_execution_time 或 max_upload_filesize 设定太小出问题。

后来在 Nginx 的 Log 找到以下错误:

client intended to send too large body: xxxxxxx bytes

出现这个错误是因为 Web Server (Nginx) 可以接收的 request body 太小, 上传的档案超出了限制所致。

Apache 的 LimitRequestBody 默认是 0, 即无限制, 但 Nginx 的 client_max_body_size 默认是 1MB, 即上传超过 1MB 档案便会出现问题。

要解决这个问题, 需要开启 Nginx 的设定档修改 client_max_body_size, 先开启 Nginx 的设定档:

/linux/nginx-config-file

  • # vi /etc/nginx/nginx.conf

在 http {} 段落里面, 加入以下一行, 将 client_max_body_size 的限制改成 20MB:

client_max_body_size 20M;

即改成类似这样:

在 vi 储存盘案及离开:

:wq

最后重新加载 Nginx 便完成了:

/linux/reload-nginx

  • # systemctl reload nginx
Tags:,

Leave a Reply