An upload form that works for small files but fails above about 1 MB is almost always the nginx 413 request entity too large error. NGINX refuses the request body before your app ever sees it. This guide shows you how to prove NGINX is the layer doing the rejecting, set client_max_body_size in the context that actually wins, and reload safely. It also covers the limits behind NGINX (PHP-FPM, your app) and in front of it (CDNs, load balancers, Kubernetes ingress).
The short answer: NGINX’s default body limit is 1m. Raise it with client_max_body_size in the http, server, or location block that handles the failing URL. Check the syntax with nginx -t, then apply the change — on most systemd-managed Linux installs that means systemctl reload nginx, which wraps NGINX’s own reload signal.
If that doesn’t fix it, another block is overriding your value, or a different layer has its own limit. The steps below show you how to tell which.
What Does NGINX 413 Request Entity Too Large Mean?
HTTP status 413 means the server refused the request because the body is larger than it allows. In NGINX, this comes from one directive. Per the ngx_http_core_module documentation (checked October 2026), when the request body is larger than client_max_body_size, NGINX returns 413 (Request Entity Too Large).
Two details matter for troubleshooting:
- NGINX can reject the request based on the
Content-Lengthheader alone. The upload never reaches PHP, Node, Python, or whatever runs behind it. That’s why your app logs show nothing. - The NGINX docs warn that browsers cannot correctly display this error. You may see a blank page, a “connection reset,” or a vague upload failure instead of a clean 413. Use
curland the NGINX error log to see what really happened.
Quick Reference: Symptom to Fix
| Symptom | Most likely layer | Fix |
|---|---|---|
curl -v shows 413 and error.log includes a line such as “client intended to send too large body” | NGINX | Raise client_max_body_size in the matching location/server block |
| You raised the limit, but 413 persists with the same log line | NGINX (override) | Find the more specific block with nginx -T and set the value there |
NGINX accepts the body, but the PHP app says the file is too big or $_FILES is empty | PHP-FPM | Raise upload_max_filesize and post_max_size, reload PHP-FPM |
| 413 appears, but there’s no NGINX error log line | Upstream app or edge layer | Bypass the edge with curl --resolve; check app and vendor limits |
| Large uploads fail partway with 408 or a timeout, not 413 | NGINX timeouts/buffering | Review client_body_timeout and proxy_request_buffering |
| Works against the origin, fails through the public hostname | CDN, cloud load balancer, or ingress | Check that vendor’s current docs for its request body limit |
What Is client_max_body_size?
client_max_body_size sets the maximum allowed size of the client request body. These facts come from the official directive reference:
| Property | Value |
|---|---|
| Syntax | client_max_body_size size; |
| Default | 1m |
| Valid contexts | http, server, location |
| Over the limit | NGINX returns 413 |
Set to 0 | Disables body size checking entirely |
Sizes typically use suffixes such as k, m, and g for kilobytes, megabytes, and gigabytes, following NGINX’s general size-notation conventions. 1m represents one megabyte in NGINX’s configuration syntax.
The context rule is where most fixes go wrong. NGINX directives inherit downward: http → server → location. The most specific block that sets the directive wins. A location block with its own client_max_body_size 1m; ignores the 100m you set in nginx.conf. The NGINX Beginner’s Guide explains how the config file nests these contexts.
Prerequisites
Commands here target Ubuntu 24.04 LTS / Debian 12 and RHEL 9-family distros (Rocky Linux, AlmaLinux). They use NGINX Open Source from your distro’s repos or from nginx.org.
- A Linux server running NGINX Open Source (Ubuntu/Debian or RHEL-family)
- SSH access with
sudorights to edit/etc/nginx/and reload services curlinstalled on the server or your workstation (sudo apt install curlorsudo dnf install curl)- The URL that’s failing, for example
https://your-server.example/upload - The rough size of the file that fails, and the largest file you actually need to accept
- (PHP apps only) PHP-FPM installed and serving the app through NGINX
- (Optional) The IP address of your origin server, so you can bypass any CDN or load balancer
| Requirement | Details |
|---|---|
| OS | Ubuntu 24.04 LTS, Debian 12, or RHEL 9-family |
| Web server | NGINX Open Source (any currently supported release) |
| Access | sudo / root |
| Site config location | Typically /etc/nginx/sites-available/ (Debian/Ubuntu) or /etc/nginx/conf.d/ (RHEL-family); verify against your own install |
| Main config | /etc/nginx/nginx.conf |
| Default error log | /var/log/nginx/error.log |
This works the same way on a production VM and on a homelab reverse proxy. Think a Raspberry Pi 5 or mini PC fronting Nextcloud, Immich, or Gitea.
Step-by-Step Guide
Step 1: Create Test Files of Known Size
Don’t debug with whatever file the user happened to upload. Create files with exact sizes so you can see where the cutoff sits.
# Create three test files: just over the 1m default, a mid-size file, and a large one
head -c 2M /dev/urandom > /tmp/upload-2m.bin
head -c 20M /dev/urandom > /tmp/upload-20m.bin
head -c 100M /dev/urandom > /tmp/upload-100m.bin
# Confirm the sizes
ls -lh /tmp/upload-*.bin
Expected output:
-rw-rw-r-- 1 youruser youruser 100M Nov 4 10:12 /tmp/upload-100m.bin
-rw-rw-r-- 1 youruser youruser 20M Nov 4 10:12 /tmp/upload-20m.bin
-rw-rw-r-- 1 youruser youruser 2.0M Nov 4 10:12 /tmp/upload-2m.bin
/dev/urandom gives you incompressible data. That matters if anything in the path compresses request bodies.
Step 2: Reproduce the 413 with curl -v
Send the 2 MB file to the failing endpoint. --data-binary sends the file exactly as-is and sets Content-Length. That’s the header NGINX checks first.
# -v prints request and response headers
# --data-binary @file sends the raw file as the POST body (curl switches to POST automatically)
curl -v --data-binary @/tmp/upload-2m.bin https://your-server.example/upload
If NGINX is rejecting the body, the output looks similar to this. Exact lines vary by curl version and TLS setup.
> POST /upload HTTP/1.1
> Host: your-server.example
> User-Agent: curl/8.5.0
> Accept: */*
> Content-Length: 2097152
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 413 Request Entity Too Large
< Server: nginx
< Content-Type: text/html
< Connection: close
<
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>
Two clues stand out. The Server: nginx header and the <center>nginx</center> footer point to NGINX’s built-in error page. An app-generated 413 usually has a different body, often JSON or the framework’s own page. Don’t treat the footer as proof yet, though. An NGINX-based CDN or ingress can produce the same page. Step 3 settles it.
Tip: For an app that requires a login, test a public upload endpoint first. You can also run the curl from a host that already has a session. You only need NGINX to receive the request. It rejects the body before authentication happens in your app.
Step 3: Find the Matching Line in the NGINX Error Log
Right after the failed curl, check the error log on the NGINX server:
sudo tail -n 20 /var/log/nginx/error.log
A body-size rejection produces a line like this:
2026/11/04 10:15:32 [error] 1234#1234: *57 client intended to send too large body: 2097152 bytes, client: 192.0.2.50, server: your-server.example, request: "POST /upload HTTP/1.1", host: "your-server.example"
Read the line field by field:
client intended to send too large body: 2097152 bytes: the declared body size. A line like this confirms NGINX itself refused the request.server: your-server.example: whichserverblock handled it. If this isn’t the server you expected, you’ve found your bug.request: "POST /upload HTTP/1.1": the URI. You’ll use it to find the matchinglocationblock.
No line? Check whether this site logs somewhere else:
# List every error_log path defined in the active configuration
sudo nginx -T | grep -n "error_log"
If there’s still no matching line anywhere, NGINX on this server did not reject the request. The 413 came from the upstream app or from something in front of NGINX. Jump to Step 4 to confirm, then go to Step 9 or Step 11.
Step 4: Bypass the Edge to Confirm Which Layer Rejects
If a CDN, cloud load balancer, or ingress controller sits in front of NGINX, test the origin directly. curl’s --resolve flag sends the request to a specific IP address while keeping the original hostname in the request.
That’s generally what TLS certificate verification and NGINX’s server_name matching rely on, so the test still exercises the right virtual host.
# --resolve host:port:ip sends the request straight to the origin, skipping DNS (and the CDN/LB)
curl -v --resolve your-server.example:443:203.0.113.10 \
--data-binary @/tmp/upload-2m.bin https://your-server.example/upload
Compare the results:
| Through public hostname | Direct to origin | NGINX error log line? | Conclusion |
|---|---|---|---|
| 413 | 413 | Yes | NGINX on the origin is the limit |
| 413 | Not 413 | No | The edge layer is the limit |
| 413 | 413 | No | The upstream app returned 413; NGINX just passed it through |
Your origin may only accept traffic from the edge provider’s IPs. In that case, run the curl from the NGINX server itself with --resolve your-server.example:443:127.0.0.1.
Step 5: Dump the Effective Configuration with nginx -T
Don’t trust that the file you’re about to edit is the one in use. nginx -T is commonly used to test the configuration and print what NGINX actually loaded, including the included files. Each file in the output starts with a # configuration file ... comment.
# -T dumps the full config; hides the "syntax is ok" lines
# grep -n shows line numbers for each file header, server, location, and body-size directive
sudo nginx -T | grep -nE "configuration file|server_name|location|client_max_body_size"
Here’s an example output that shows the classic override problem:
1:# configuration file /etc/nginx/nginx.conf:
24: client_max_body_size 100m;
58:# configuration file /etc/nginx/sites-enabled/example.conf:
62: server_name your-server.example;
70: location / {
76: location /upload {
77: client_max_body_size 1m;
84: location ~ \.php$ {
The 100m at the http level looks like it should cover everything. But location /upload sets its own 1m, and the more specific block wins. That’s why “I already raised it in nginx.conf” so often changes nothing.
Check these three things in the dump:
- Is your file actually included? If the file you edited doesn’t show up as a
# configuration fileheader, NGINX isn’t loading it. On Debian/Ubuntu’s typical layout, files insites-available/only load when they’re symlinked intosites-enabled/. - Which
serverblock matches? Compare theserver_nameagainst theserver:field from Step 3. A request can land in a default server you forgot about. - Which
locationhandles the URI? For PHP apps,try_filesoften rewrites the request internally to/index.php. It then lands in thelocation ~ \.php$block. Make sure the value you need applies there as well as inlocation /.
To see the full block around a directive, widen the view:
# -B5 shows 5 lines before each match so you can see the enclosing block
sudo nginx -T | grep -n -B5 "client_max_body_size"
Step 6: Set client_max_body_size in the Right Context
Open the site file that handles the failing route.
On Debian/Ubuntu:
sudo nano /etc/nginx/sites-available/example.conf
On RHEL-family:
sudo nano /etc/nginx/conf.d/example.conf
Pick your scope on purpose:
locationlevel: only that route accepts big uploads. This is the safest option.serverlevel: every route on that site gets the limit.httplevel (in/etc/nginx/nginx.conf): every site on the box gets it, unless a block overrides it.
A sensible pattern keeps a modest site-wide limit and raises it only where uploads happen:
# /etc/nginx/sites-available/example.conf (Debian/Ubuntu)
# /etc/nginx/conf.d/example.conf (RHEL-family)
server {
listen 443 ssl;
server_name your-server.example;
# Site-wide default for normal form posts and API calls
client_max_body_size 10m;
location / {
proxy_pass http://127.0.0.1:8080;
}
location /upload {
# Only this route accepts large bodies; overrides the server-level 10m
client_max_body_size 200m;
proxy_pass http://127.0.0.1:8080;
}
}
For a PHP app, set it where the PHP request is actually handled:
# /etc/nginx/sites-available/example.conf (Debian/Ubuntu)
server {
listen 443 ssl;
server_name your-server.example;
root /var/www/example;
# Covers location / and the PHP location below, since neither overrides it
client_max_body_size 64m;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
The snippets/fastcgi-php.conf include and the php8.3-fpm.sock path are Debian/Ubuntu conventions. On RHEL-family systems, the socket is usually /run/php-fpm/www.sock. Keep whatever your existing config already uses.
Size the limit a little above your largest real file. Browser uploads use multipart encoding, which adds some overhead on top of the raw file size. If you need to accept 50 MB files, 64m gives you headroom.
If Step 5 showed an overriding directive, either raise that value or delete the line so the block inherits from its parent.
Step 7: Test the Syntax with nginx -t
It’s good practice to check the syntax before you reload — reloading doesn’t automatically validate your changes for you:
sudo nginx -t
Expected output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If you see an error instead, it names the file and line, for example invalid number of arguments in "client_max_body_size" directive in /etc/nginx/sites-enabled/example.conf:12. The usual causes are a missing semicolon or a directive in a context where it isn’t allowed. Fix the error and run nginx -t again.
Warning: Fix every reported error before you reload. When a reload hits invalid config, the NGINX master process keeps running the old configuration. Depending on your distro’s systemd unit,
systemctl reloadmay not make that obvious. You’ll think your change is live when it isn’t.
Step 8: Reload NGINX and Verify the Change
A reload applies the new config without dropping active connections. On a systemd-managed install, systemctl reload nginx triggers NGINX’s reload process: it starts new worker processes and lets the old ones finish requests already in progress.
sudo systemctl reload nginx
sudo systemctl status nginx --no-pager
Expected output includes:
● nginx.service - A high performance web server and a reverse proxy server
Active: active (running) since ...
The description line differs by distro. What matters is active (running).
Now confirm the running config contains your value:
sudo nginx -T | grep -n -B5 "client_max_body_size"
Then repeat the test from Step 2:
curl -v --data-binary @/tmp/upload-2m.bin https://your-server.example/upload
Success means NGINX’s 413 page is gone and no new “too large body” line appears in error.log. The response now comes from your backend. That might be 200. It might also be 400, 405, or 422 if the endpoint expects a multipart form and gets a raw body. That’s fine, because NGINX passed the body through. Repeat with /tmp/upload-20m.bin and /tmp/upload-100m.bin to confirm the new ceiling sits where you expect.
If the backend now answers with a 502 or 504 on large files, NGINX accepted the upload. The upstream then failed or timed out while handling it. That’s a different problem. Troubleshoot it as a 502 Bad Gateway / upstream timeout issue.
Step 9: Raise PHP-FPM’s upload_max_filesize and post_max_size
PHP has its own limits, and NGINX knows nothing about them. The two that matter are documented in the PHP manual’s core php.ini directives:
upload_max_filesize: the maximum size of a single uploaded filepost_max_size: the maximum size of the entire POST body. It must be greater than or equal toupload_max_filesize, because the body contains the file plus form fields.
Defaults differ between PHP builds and distro packages, so check what your server actually has. Don’t assume. PHP limits usually don’t cause a 413. Typical symptoms are an app error such as “file exceeds the maximum upload size,” or an empty $_POST/$_FILES when post_max_size is exceeded.
First, find the FPM config. Don’t confuse it with the CLI php.ini, which is a separate file and generally won’t reflect what FPM loads.
On Debian/Ubuntu (the PHP version in the path varies; Ubuntu 24.04 ships PHP 8.3):
# List FPM php.ini files for every installed PHP version
ls /etc/php/*/fpm/php.ini
# List any conf.d overrides, then check the pool file for the values that will actually apply
ls /etc/php/*/fpm/conf.d/
grep -E "upload_max_filesize|post_max_size" /etc/php/*/fpm/pool.d/www.conf
On RHEL-family:
grep -E "upload_max_filesize|post_max_size" /etc/php.ini
ls /etc/php.d/
grep -E "upload_max_filesize|post_max_size" /etc/php-fpm.d/www.conf
php-fpm -i and similar CLI-style flags on the FPM binary aren’t dependable across distro packages. The FPM master commonly doesn’t expose that information output consistently, and the executable name and version vary enough that you may get an “invalid option” error or end up inspecting the wrong SAPI’s config. Treat plain php -i as CLI-only; it never reflects what FPM itself loaded.
Where your package supports it, sudo php-fpm8.3 -tt (or sudo php-fpm -tt on RHEL-family) tests the configuration and prints the resolved pool settings, which is a more reliable way to confirm what a given pool will actually use. If you need certainty about live, request-time values, drop a temporary script such as <?php phpinfo(); ?> into a path served through the same NGINX+FPM route, restrict it with authentication or an IP allowlist, check it, and delete it immediately afterward.
Skip editing the main php.ini and add a small override file. It survives package upgrades more cleanly.
On Debian/Ubuntu:
; /etc/php/8.3/fpm/conf.d/99-uploads.ini
; post_max_size must be >= upload_max_filesize
upload_max_filesize = 50M
post_max_size = 64M
On RHEL-family:
; /etc/php.d/99-uploads.ini
upload_max_filesize = 50M
post_max_size = 64M
Match these to your NGINX value. Here, NGINX allows 64m and PHP allows the same total body. A file limit larger than NGINX’s limit is pointless, because NGINX rejects the request first.
Also check for pool-level overrides. They win over php.ini:
# Debian/Ubuntu pool files
sudo grep -rn -E "upload_max_filesize|post_max_size" /etc/php/*/fpm/pool.d/
# RHEL-family pool files
sudo grep -rn -E "upload_max_filesize|post_max_size" /etc/php-fpm.d/
A line like php_admin_value[upload_max_filesize] = 2M in a pool file overrides your .ini change for that pool.
Reload PHP-FPM so the workers pick up the new values.
On Debian/Ubuntu:
sudo systemctl reload php8.3-fpm
On RHEL-family:
sudo systemctl reload php-fpm
If the values don’t change after a reload, use restart. Then re-check the pool file, conf.d overrides, or your temporary diagnostic script to confirm the new values actually took effect. The PHP manual also advises that memory_limit should generally be larger than post_max_size. Raise it if your app processes uploads in memory.
Your app may still have its own cap on top of PHP. WordPress, Nextcloud, and most frameworks have one. Check the app’s admin settings or config file if uploads still fail with an app-level message.
Step 10: Check Timeouts and Buffering for Large or Slow Uploads
Once the size limits are right, very large uploads over slow links can still fail. Two NGINX settings are the usual suspects.
client_body_timeout (default 60s, valid in http, server, location). Per the core module docs, this timer covers the gap between two successive reads of the request body, so total upload time isn’t capped. If the client sends nothing for that long, NGINX ends the request with 408 (Request Time-out). A steady slow upload usually survives. One that stalls, such as on a flaky mobile connection, may not.
# /etc/nginx/sites-available/example.conf (inside the upload location)
location /upload {
client_max_body_size 200m;
client_body_timeout 120s; # allow longer gaps between reads on slow links
proxy_pass http://127.0.0.1:8080;
}
proxy_request_buffering (default on, from ngx_http_proxy_module). With buffering on, NGINX reads the entire body before passing it to the upstream. Bodies larger than the in-memory buffer go to a temporary file on disk. The upstream gets the whole upload at once.
The trade-off: you need free disk space for big uploads. NGINX logs a warning (“a client request body is buffered to a temporary file”) when this happens. Put the temp path on a fast SSD with room to spare.
With proxy_request_buffering off;, NGINX streams the body to the upstream as it arrives. That cuts disk use and latency. But the upstream holds a connection open for the entire upload. NGINX also can’t retry the request on another upstream server once it has started sending. For PHP-FPM, the equivalent directive is fastcgi_request_buffering.
# Stream large uploads straight to the backend instead of buffering to disk
location /upload {
client_max_body_size 2g;
proxy_request_buffering off;
proxy_pass http://127.0.0.1:8080;
}
I’d only turn buffering off for routes where your backend handles streamed uploads well. That’s common for apps like Immich or Nextcloud that write straight to a NAS. Leave it on everywhere else.
Step 11: Clear Limits at the Edge (CDN, Load Balancer, Kubernetes Ingress)
If Step 4 showed that the origin accepts the upload but the public hostname doesn’t, NGINX is off the hook. Every layer in front of it can enforce its own, independent request body limit. Your client_max_body_size has no effect on them.
- CDNs and reverse-proxy services: many cap request body size, and some caps depend on the plan. Check your provider’s current docs for request or upload limits. Large uploads may need to go to a hostname that isn’t proxied through the CDN.
- Cloud load balancers: each vendor documents its own request size and timeout limits. Look them up for the specific load balancer type you use.
- Kubernetes ingress controllers: the ingress is a separate proxy, often NGINX-based, with its own config. Editing an NGINX config inside your app’s pod won’t change it. How you raise the limit depends on which controller you run:
- F5’s NGINX Ingress Controller documents a
nginx.org/client-max-body-sizeannotation in its annotations reference. - NGINX Gateway Fabric (Gateway API) uses a different model. It’s a
ClientSettingsPolicywith abody.maxSizefield, documented under Client Settings. Don’t mix up the two. - Other ingress controllers use different annotation names. Check the docs for the exact controller and version in your cluster before you copy an annotation from a forum post.
- F5’s NGINX Ingress Controller documents a
Retest with the Step 2 command through the public hostname after each change.
Configuration Reference
| Directive | Default | Contexts | What it controls |
|---|---|---|---|
client_max_body_size | 1m | http, server, location | Max request body size; over limit returns 413; 0 disables the check |
client_body_timeout | 60s | http, server, location | Max gap between reads of the body; expiry returns 408 |
proxy_request_buffering | on | http, server, location | Buffer full body before proxying (on) or stream it (off) |
fastcgi_request_buffering | on | http, server, location | Same idea for FastCGI/PHP-FPM upstreams |
upload_max_filesize (PHP) | Varies by build | php.ini / FPM pool | Max size of a single uploaded file |
post_max_size (PHP) | Varies by build | php.ini / FPM pool | Max size of the whole POST body; must be ≥ upload_max_filesize |
Is It Safe to Set client_max_body_size to 0?
Setting it to 0 disables the size check entirely. It does fix the 413, but it’s rarely the right fix. With buffering on, NGINX will write arbitrarily large bodies to disk. One client can fill the disk or tie up workers and backend connections. Your PHP or app limits still apply, but only after NGINX has accepted and buffered the whole body.
A better pattern is a specific number on the specific location that needs it. Use a generous value (2g) for a dedicated, authenticated upload route if you must. Use 0 only on a route where something else already limits who can send traffic and how much.
Tips and Troubleshooting
Error: Still getting 413 after raising client_max_body_size
Why it happens: A more specific location or server block sets its own value. It might also be a different server block that you didn’t edit. Sometimes the PHP request lands in location ~ \.php$ after a try_files rewrite.
Fix:
- Run
sudo nginx -T | grep -n -B5 "client_max_body_size"to list every occurrence. - Match the
server:andrequest:fields from the error log line to aserver_nameandlocation. - Set or remove the directive in that block. Then run
sudo nginx -tandsudo systemctl reload nginx.
Error: Edited the config and reloaded, but nothing changed
Why it happens: The edited file isn’t included. Common cases are a sites-available/ file that was never symlinked, or a file outside the include glob. Or the reload failed on a syntax error and NGINX kept the old config.
Fix:
- Check
sudo nginx -T | grep "configuration file"for your file’s path. - On Debian/Ubuntu, enable it with
sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/. - Run
sudo nginx -t, then reload, then confirm the value appears innginx -T.
Error: NGINX accepts the upload, but the PHP app still rejects it
Why it happens: upload_max_filesize or post_max_size is too low. Maybe you edited the CLI php.ini and missed the FPM one. A pool file may override the value, or PHP-FPM wasn’t reloaded.
Fix: Follow Step 9. Confirm the resolved values through the FPM php.ini, conf.d overrides, and pool file — or a temporary diagnostic script served through FPM — rather than relying on php -i, which only reports the CLI SAPI’s configuration and tells you nothing about what FPM loaded.
Error: Large uploads fail partway with 408, a timeout, or a reset
Why it happens: client_body_timeout expired during a stall, or the temp disk filled while buffering. Upstream timeouts can also cut off slow processing of a big file.
Fix: Raise client_body_timeout on the upload route. Check free space with df -h /var/lib/nginx (Debian/Ubuntu) or df -h /var/lib/nginx/tmp (RHEL-family). Consider proxy_request_buffering off; for streaming-capable backends. If you get 504s, look at the upstream timeouts.
Error: 413 only through the public URL, with no NGINX error log entry
Why it happens: A CDN, cloud load balancer, or ingress controller rejected the body before it reached your NGINX.
Fix: Confirm with the curl --resolve test in Step 4. Then raise the limit in that layer, using its current vendor docs (Step 11).
Error: The browser shows a blank page or “connection reset” instead of 413
Why it happens: As the NGINX docs note, browsers can’t correctly display this error in some cases. NGINX may close the connection while the browser is still sending the body.
Fix: Don’t debug from the browser. Use curl -v plus the error log (Steps 2–3) to see the real status code.
Extra Tips
- Keep limits close to the route: set a big limit on
/uploador/remote.php(Nextcloud’s WebDAV path) and leave the rest of the site small. This also limits damage from oversized junk POSTs to login forms. - Log the request size: add
$request_lengthto a customlog_format. It shows you how big real uploads are, so you can size the limit from data. - Align every layer: edge ≥ NGINX ≥ PHP
post_max_size≥upload_max_filesize≥ app setting. The smallest one wins, so write the chain down for each site. - TLS doesn’t change any of this: if you just put HTTPS in front of a service, the body limits apply the same way. Remember to set them in the new TLS
serverblock, though. The old port-80 block won’t cover it.
Wrapping Up
The 413 itself is a one-line fix. The hard part is finding the layer that actually rejected the request. Reproduce with a known-size file, confirm the “too large body” line in the error log, and read the merged config with nginx -T before you touch anything. That routine turns a guessing game into a two-minute fix, and it catches the overriding location block that defeats most copy-pasted answers.
Resist client_max_body_size 0. A specific, generous limit on the upload route gives users the same experience without leaving your disk open to whoever sends the biggest POST.
| Step | Action | Applies To |
|---|---|---|
| 1–2 | Create known-size files, reproduce with curl -v | All setups |
| 3–4 | Read error.log, bypass the edge with --resolve | All setups |
| 5 | Find the winning block with nginx -T | NGINX |
| 6–8 | Set client_max_body_size, nginx -t, reload, verify | NGINX |
| 9 | Raise upload_max_filesize / post_max_size, reload PHP-FPM | PHP apps |
| 10 | Tune client_body_timeout, request buffering | Large/slow uploads |
| 11 | Raise CDN / load balancer / ingress limits | Edge-fronted sites |