Limit File Upload Size in NGINX

By limiting the file size of uploads, you can prevent some types of Denial-of-service (DOS)
attacks and many other issues. By default, NGINX® has a upload limit of 1 MB per file.
By editing client_max_body_size, you adjust the file upload size.

Use the http, server, or location block to edit client_max_body_size.

  • Changes to the http block affect all server blocks (virtual hosts).
  • Changes to the server block affect a particular site or application.
  • Changes to the location block affect a particular directory for uploads under a site
    or application.

Edit the upload file size value

  1. Edit the /etc/nginx/nginx.conf file to increase the limit of the files to upload:

    • http:

       http {
       client_max_body_size 100M;
    • server:

       server {
       client_max_body_size 100M;
    • location:

       location /uploads {
       client_max_body_size 100M;
  2. Save the file and restart the NGINX webserver to apply the changes:

    • systemd

      systemctl restart nginx

    • sysvinit

      service nginx restart

Note: sudo nginx -s reload reloads the configuration without restarting nginx.

Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.