How to setup NGINX Request Body Size

Last updated: September 4, 2025

Setup NGINX Request Body Size

  1. Access your NGINX configuration file (typically located at /etc/nginx/nginx.conf)

  2. Locate the http, server, or location context where you want to modify the request body size

  3. Add or modify the following directive:

    client_max_body_size 20M;

    Note: Replace 20M with your desired maximum file size (e.g., 50M for 50 megabytes, 1G for 1 gigabyte)

  4. Save the configuration file

  5. Restart NGINX to apply the changes:

    sudo systemctl restart nginx

    or

    sudo service nginx restart

Usage

After configuring the client_max_body_size, NGINX will accept file uploads up to the specified size limit. If a user attempts to upload a file larger than the configured limit, NGINX will return a 413 (Request Entity Too Large) error.

You can set different limits for different locations by adding the directive in specific location blocks:

location /upload {
    client_max_body_size 100M;
}

location /api {
    client_max_body_size 10M;
}