Change the file upload size in NGINX

Add RSS feed to Reader and sync to Readwise.

When you have a PHP-based website like WordPress running on NGINX, you would typically change the maximum file upload size in PHP settings e.g., in php.ini file or similar.

NGINX web server also has it’s own configuration where you can set the max upload size server-wide. This is set in the .conf file using the client_max_body_size directive.

To set the maximum upload site server-wide (for all sites on the server)

Find the NGINX config file which is usually located at /etc/nginx/nginx.conf. Open the file and set the directive in the http block.

http {
  #   ...
  client_max_body_size 100M;
  # Sets the maximum file upload size to 100MB.
}
Code language: PHP (php)

To set the maximum upload site for a particular site running on the server

Find the site’s config file which is usually located at /etc/nginx/sites-enabled/website-name.conf or /etc/nginx/conf.d/website-name.conf. Open the file and set the directive in the server block.

server {
  # ...
  client_max_body_size 100M;
}
Code language: PHP (php)

To set the maximum upload site for a particular folder on the server

You can set this in the site’s config file. Open the .conf file and set the directive in the location block. The folder needs to exist under the website’s folder. In this example, the folder /uploads needs to exist.

location /uploads {
  # ...
  client_max_body_size 100M;
}
Code language: PHP (php)

Restart NGINX

Make sure to restart NGINX after setting any of these options by running:

systemctl restart nginx
service nginx restart

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *