Troubleshooting

Fix "413 Request Entity Too Large" on uploads

Fix 413 errors when uploading files: raise client_max_body_size in Nginx, LimitRequestBody in Apache, PHP upload limits, and proxy or CDN limits in front of the server.

BeginnerLinux VPS3 min read

413 Request Entity Too Large means the web server rejected an upload or form post because the request body exceeded its limit. Nginx's default limit is only 1 MB, so this error commonly appears when uploading images, themes, plugins or database imports on a fresh VPS.

Before you start

  • Root access to the server.
  • The size of the file you need to upload; set limits a little above it.

Raise the Nginx limit

Add client_max_body_size in the http, server or a specific location block:

server {
    server_name example.com;
    client_max_body_size 64m;
    ...
}

Test and reload:

nginx -t && systemctl reload nginx

Setting it per server or location keeps large uploads limited to the sites that need them. If Nginx is a reverse proxy in front of another server or container, the backend may have its own limit too.

Raise the Apache limit

Apache allows large bodies by default, but configurations sometimes set LimitRequestBody. Increase or remove it (value in bytes):

LimitRequestBody 67108864

ModSecurity rules can also block large bodies (SecRequestBodyLimit); check its audit log if Apache returns 413.

Match the PHP limits

After the web server accepts the request, PHP has its own limits. If they are lower, the upload fails differently (an empty $_FILES, or the app reports the file exceeds the maximum size). In php.ini for PHP-FPM:

upload_max_filesize = 64M
post_max_size = 72M
max_execution_time = 120

post_max_size must be larger than upload_max_filesize. Reload PHP-FPM afterwards. On cPanel hosting set the same values under Select PHP Version → Options.

Check limits in front of the server

  • Cloudflare: the free and Pro plans limit request bodies to 100 MB; larger uploads must bypass the proxy (a DNS-only subdomain) or use chunked uploads.
  • Load balancers and ingress controllers (Traefik, Kubernetes ingress-nginx) have their own body size settings, e.g. the nginx.ingress.kubernetes.io/proxy-body-size annotation.
  • Application limits: WordPress shows the effective maximum in Media → Add New; Nextcloud, Moodle and others have their own settings.

Check the fix

Upload the file again. To test from the command line:

head -c 30M /dev/urandom > /tmp/test.bin && curl -s -o /dev/null -w '%{http_code}\n' -F 'file=@/tmp/test.bin' https://example.com/upload-endpoint

A 413 means a server or proxy limit; a different status means the request passed the web server.

Troubleshooting

  • Still 413 after changing Nginx: a more specific location or another included file sets a lower value, or you edited a config that is not loaded. nginx -T | grep client_max_body_size shows every setting.
  • Upload stops without 413: PHP limits or max_execution_time; check the PHP error log.
  • Large database imports: use the command line (mysql db < dump.sql) instead of phpMyAdmin uploads.

413 error FAQ

What limit should I set?

Just above the largest file users genuinely need to upload. Very large limits make it easier to abuse upload endpoints.

Does 413 happen on cPanel hosting?

Rarely from the web server; upload limits there are usually PHP settings you can change in cPanel.

Does client_max_body_size affect downloads?

No, only request bodies sent to the server.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.