Fix Nginx 413 Request Entity Too Large with client_max_body_size
Upload failing with 413? Find the too large body line in error.log and raise client_max_body_size. Covers the 1m default, which block wins and what 0 means.
An upload that comes back as 413 Request Entity Too Large was stopped by Nginx's request body limit. One directive, client_max_body_size, sets it, and the block you put it in decides the result. The output below comes from Nginx on port 18611 receiving a 2 MiB (2097152-byte) file.
[1] Confirm the 413 came from Nginx by checking error.log. The line below means it did. N bytes is the size of the request body; the client and server fields are shortened to ….
# nginx -T 2>/dev/null | grep error_log# tail -n 5 /var/log/nginx/error.log… [error] … *1 client intended to send too large body: 2097152 bytes, …, request: "POST /upload HTTP/1.1", host: "…"[2] Reproduce it. With no client_max_body_size in the config, the default 1m applies. This sends 2 MiB to a server that only does return 200.
$ head -c 2M /dev/zero > big.bin$ curl -si --data-binary @big.bin http://127.0.0.1:18611/upload | head -4HTTP/1.1 413 Request Entity Too LargeServer: nginx/1.24.0 (Ubuntu)Date: Mon, 19 Oct 2026 03:52:22 GMTContent-Type: text/html[3] Check the boundary. The default 1m is 1048576 bytes. A body of exactly that size passes; one byte more is rejected.
$ head -c 1048576 /dev/zero | curl -s -o /dev/null -w '%{http_code}\n' --data-binary @- http://127.0.0.1:18611/upload200$ head -c 1048577 /dev/zero | curl -s -o /dev/null -w '%{http_code}\n' --data-binary @- http://127.0.0.1:18611/upload413[4] Find where the directive is set in the running config. If nothing shows up, the default 1m is in effect.
# nginx -T 2>/dev/null | grep -n client_max_body_size[5] Add the value to the server block. The directive is allowed in http, server and location. Pick a limit a little above the largest single upload you expect.
server { listen 18611; client_max_body_size 10m; location / { return 200 "ok\n"; }}Test the syntax and reload. The same request now passes (in the test, Nginx was started fresh instead of reloaded).
# nginx -t && systemctl reload nginx$ curl -s -o /dev/null -w '%{http_code}\n' --data-binary @big.bin http://127.0.0.1:18611/upload200[6] The innermost block wins. Set 10m in http and 1m only in location /small/, and the same 2 MiB passes at /upload but fails at /small/x.
http { client_max_body_size 10m; server { listen 18611; location / { return 200 "ok\n"; } location /small/ { client_max_body_size 1m; return 200 "ok\n"; } }}$ curl -s -o /dev/null -w '/upload %{http_code}\n' --data-binary @big.bin http://127.0.0.1:18611/upload/upload 200$ curl -s -o /dev/null -w '/small/x %{http_code}\n' --data-binary @big.bin http://127.0.0.1:18611/small/x/small/x 413It works the other way too: keep 1m in http and open only the upload path. In the test, http 1m + server 3m + location 2m let 2 MiB through (the location value applied), while location 2097151 — one byte short — returned 413. Opening just the upload path beats raising the limit everywhere.
[7] 0 turns the check off. The docs: "Setting size to 0 disables checking of client request body size." In the test, with http 1m and 0 in location /big/, 2 MiB passed at /big/x and got 413 at /upload. With no limit left, use it only on paths such as ones behind authentication.
$ curl -s -o /dev/null -w '/big/x %{http_code}\n' --data-binary @big.bin http://127.0.0.1:18611/big/x/big/x 200[8] If uploads still fail, the app behind Nginx may enforce its own limit. PHP has upload_max_filesize (default 2M) and post_max_size (default 8M); its manual says post_max_size must be larger than upload_max_filesize. Change both in php.ini, and check any other proxy in front. PHP was not reproduced here.
| Where the limit is set | Default | When exceeded |
|---|---|---|
Nginx client_max_body_size | 1m | 413 · client intended to send too large body |
PHP upload_max_filesize | 2M | per the manual — the file is not uploaded |
PHP post_max_size | 8M | per the manual — $_POST and $_FILES are empty |
Sources: nginx.org — client_max_body_size · PHP manual — upload_max_filesize, post_max_size
Analyze your Nginx log in the browser ↗ — nothing is uploaded.