上传图片文件过大,导致Nginx报错client intended to send too large body: 3776747 bytes,解决办法是对Nginx的clientmaxbodysize。 环境. Nginx/1.14.0 (CentOS). nginx 錯誤,client intended to send too large body. 2017-09-09 a556622822. 之前因為把機器上原本的 apache 的 web server 換成 nginx,遇到了這個錯誤 client intended to send too large body. 查了一下資料發現造成的原因為 web server 接收 request body 的大小設定.
When I try to upload a file to my site, I'm getting the Nginx '413 Request Entity Too Large' error, however in my nginx.conf file I've already explicitly stated the max size to be about 250MB at the moment, and changed the max file size in php.ini as well (and yes, I restarted the processes). The error log gives me this:
2010/12/06 04:15:06 [error] 20124#0: *11975 client intended to send too large body: 1144149 bytes, client: 60.228.229.238, server: www.x.com, request: 'POST /upload HTTP/1.1', host: 'x.com', referrer: 'http://x.com/'
As far as I know, 1144149 bytes isn't 250MB...Is there something I'm missing here?
Here's the base Nginx config:
And the vhost for the site:
EJay
EJayEJay
3 Answers
Not knowing the version of your nginx build and what modules it was built with makes this tough, but try the following:
-
Copy your client_max_body_size 300M; line into the location / { } part of your vhost config. I'm not sure if it's overriding the default (which is 1 MB) properly.
-
Are you using nginx_upload_module? If so make sure you have the upload_max_file_size 300MB; line in your config as well.
A. R. YounceA. R. Younce
My setup was:
php.ini
nginx.conf
The nginx showed the error 413 when it was uploaded.
Then I had an idea: I will not let nginx show the error 413, client_max_body_size set to a value greater than upload_max_filesize, thus:
php.ini
nginx.conf
What happened?
When you upload smaller than 80MB nginx will not display the error 413, but PHP will display the error if the file is up to 8MB.
This solved my problem, but if someone upload a file larger than 80MB error 413 happens, nginx rule.
renedetrenedet
I also add that you could define it in the *.php location handler
Being the 'lower' one in the cascading level, it would be an easy way to see if the problem comes from your nginx config or modules.
It sure doesn't come from PHP because the 413 error 'body too large' is really a NGinx error.
nembletonnembleton
Not the answer you're looking for? Browse other questions tagged phpfile-uploadnginx or ask your own question.
I want to allow client to upload files on our system, and I want them to be able to upload files larger than the default body set in nginx.
So I've set the following in our site configuration:
So far, so good, but I really only need this larger body size on a single URL; the one users
POST
to.
So I've tried the following configuration:
But this doesn't work at all, I get the following error in the log:
2016/04/24 13:52:51 [error] 17853#0: *1569513 client intended to send too large body: 1083334 bytes, client: 203.0.113.7, server: example.com, request: 'POST /api/files HTTP/1.1', host: 'example.com'
So I tried the following change:
But this just results in a different error:
2016/04/24 14:25:50 [error] 19500#0: *171 open() '/usr/share/nginx/html/api/files' failed (2: No such file or directory), client: 203.0.113.7, server: example.com, request: 'POST /api/files HTTP/1.1', host: 'example.com'
This makes me assume that
location
actually refers to locations on the local file system, even though the documentation says:
Sets configuration depending on a request URI.
So, how do I apply this configuration change for this single request location only?
Der HochstaplerDer Hochstapler
1 Answer
I think the solution lies in a nested location. So 'location /api/files 'should be inside your php location block.Your fastcgi config should be inherited to the 'files' location.
If you have location /api/files outside your php location nginx would find 'api/files' and remember it. But before using it, it would check whether there is a location with a matching regular expression, which would be the php location for php file requests. It would then use the php location and discard 'location api/files'.
JosefScriptJosefScript