basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    HTTP 413 in nginx — default 1m client_max_body_size and PHP limits

    By default nginx rejects any request body larger than 1m with 413 Request Entity Too Large. Raise the limit only in the server or location that needs it, and for PHP sites raise upload_max_filesize and post_max_size to match.

    Where to raise the limit

    Keeping client_max_body_size 1m; globally in http and raising it only on the upload route is safer than opening 100m for every site on the server (Hardening):

    location /upload {
        client_max_body_size 64m;
        client_body_timeout  60s;
        proxy_pass http://127.0.0.1:3000;
    }

    For PHP-FPM on Ubuntu 24.04, also update /etc/php/8.3/fpm/php.ini (on Ubuntu 26.04, /etc/php/8.5/fpm/php.ini):

    upload_max_filesize = 64M
    post_max_size = 68M

    If it doesn’t work

    Uploading a 3 MB photo fails immediately with 413 Request Entity Too Large before reaching the app

    Cause
    client_max_body_size isn’t set, so nginx enforces its 1m default.
    Fix
    Add client_max_body_size 32m; to the target location or server, then run sudo nginx -t && sudo systemctl reload nginx.

    Setting client_max_body_size 64m; cleared 413, yet WordPress still rejects files over 2 MB

    Cause
    PHP’s own limits in /etc/php/8.3/fpm/php.ini kicked in: upload_max_filesize = 2M and post_max_size = 8M.
    Fix
    Raise both settings in php.ini (keep post_max_size slightly larger than upload_max_filesize) and reload php8.3-fpm (PHP-FPM).