Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tahertechs's avatar

413 Request Entity Too Large (nginx/1.6.2)

Just wondering if anyone have faced the problem am facing right now. I have just added my site to forge and trying to post images which has a total size of 1.51 MB (No file has a maximum of 500KB ) but I get "413 Request Entity Too Large" error. Am using laravel forge. I Don't know how to fix this. Any help really appreciated. (In my development environment everything works fine ).

0 likes
38 replies
bashy's avatar
bashy
Best Answer
Level 65

Have a check of the client_max_body_size as the default is 1MB. /etc/nginx/nginx.conf

Syntax: client_max_body_size size;
Default:    client_max_body_size 1m;
Context:    http, server, location

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://nginx.org/en/docs/http/ngx_http_core_module.html

I normally set mine to

client_max_body_size 100M;

And to check PHP settings

grep -E "upload_max_filesize|memory_limit|post_max_size" /etc/php5/fpm/php.ini

15 likes
tahertechs's avatar

Thanks for quick response , Let me try and I'll respond soon

bashy's avatar

No problem, kinda live on this forum :P

No reason why it shouldn't work!

4 likes
tahertechs's avatar

Hey bashy , I was working on the issue and here is where I got stuck ,First, i couldn't find the line "client_max_body_size " in my conf file and so I had to add it within http context, but still getting the same error. Also I can only see event, http, and mail context , neither server nor location in my config file. Not sure if am adding the line where it is supposed to be. Please help

tahertechs's avatar

BTW am new to command line editor like vim so I had to read tutorial on how to use it :D , that's why I respond late

bashy's avatar

Seems fine. Have you restarted nginx and php5-fpm?

tahertechs's avatar

When I reload nginx I got this error : "client_max_body_size" directive invalid value in /etc/nginx/nginx.conf . That is the line I have added.

bashy's avatar

Screenshot of conf seems to have 404'd so can't see it. Copy the line you added here again? Might be missing a semicolon.

tahertechs's avatar

I have changed "MB to M" i.e.50MB to 50M and now it is working...Really appreciate your help @bashy

bashy's avatar

Oh right, yeah it's just M, no B needed :)

No problem, enjoy Laravel and Linux!

2 likes
jbreuer95's avatar

Hello Everyone,

So i have the same problem. i use Forge with a load balancer. I changed the php.ini settings on both nodes and added client_max_body_size 10M in the http part of both nginx.conf After a restart i still get 413 (Request Entity Too Large) on my POST.

Has this method changed in 5 months because i'm clueless i hope someone can help :)

bashy's avatar

@tsm200 No it has not and it could be another setting stopping you. What exactly are you uploading/sending in the form? (Sizes/amount of fields etc).

jbreuer95's avatar

@bashy I'm trying to upload 1 image at the time, when the size is above 1.5 MB i get the 413

bashy's avatar

@tsm200 Could be because of something else then. Can you show me both the PHP settings and Nginx?

bashy's avatar

@tsm200 By the way, post_max_size should be larger than upload_max_filesize since you should be able to upload a file and allow for other POST data. Other than that I'm not sure why it's not working.

1 like
jbreuer95's avatar

@bashy Finally it hit me! I set everything fine on my nodes but i forgot to set client_max_body_size 10M to my loadbalancer :S Thanks for the help!

jclermont's avatar

FYI, this is now a configuration setting in Forge: Server Details -> Meta. You can specify a max file size in megabytes. This updates PHP and nginx.

5 likes
Miel's avatar

@jclermont thanks this was helpful, but now 7 years later you can specify the max file upload size in the server php tag.

1 like
Ace's avatar

@jclermont how do you set it up in forge?

Server Details -> Meta. You can specify a max file size in megabytes. This updates PHP and nginx.

thanks

1 like
sharelov's avatar

One bit of info on this - if you went ahead and tried to manually change this on nginx.conf and php.ini - don't just go and try it on forge. It will cause a duplicate client_max_body_size directive, causing your nginx service to fail on startup because the conf file tests will fail due to that duplicate directive.

This seems to be because, at the time of writing this, Forge updates a different conf file uploads.conf. I did not bother to look for the location of this file, however I quickly undid my edit of the nginx.conf and simply resolved the issue by managing this from forge like the rest of the stuff i normally do on the server.

It seems to have resolved the 413 error for now, as I have gotten no new reports of it and my tests couldn't replicate any new 413 errors.

1 like
Nicholaus's avatar

Forge really needs to add a note to the "Max File Upload Size" form clearly stating that it changes nginx config too.

4 likes
cameronwilby's avatar

I found the setting on Forge under Server Details > PHP

4 likes
Gass's avatar

In Forge click on sites at the top then select your server -> PHP and the first card at the top named "Max File Upload Size" enter the max size in MB and save. After that restart your PHP server by clicking the restart button on the bottom of this same page.

automica's avatar

Admirable answer to 6 year old question though

dev96xp's avatar

How can i change this value on laravel forge ?

virtualmayur's avatar

Hello @bashy @jbreuer95, I am trying to post a file in base64 in the request and getting the same error in laravel 5.4 in PHP 7.4, I have already changed Nginx conf and php.ini but still getting the same error. Can anyone please help me with that?

client_max_body_size 100M;

in php.ini

upload_max_filesize 100M;
post_max_size 100M;
memory_limit 120M;
Sinnbeck's avatar

@virtualmayur If you want help, it is always better to make a new thread. This thread is already solved, so the changes of anyone noticing it is very slim.

Please or to participate in this conversation.