Skip to content Skip to sidebar Skip to footer

How to Increase Php Upload Limits in Nginx

Configuring Nginx and PHP 7 stack in Linux to increase or subtract file upload size limit

PHP web applications can utilize Nginx as the opposite proxy server and PHP FPM as the upstream server. Whenever you encounter HTTP file upload issues, limitation in file upload size is one common crusade.

This post shows how to accommodate the file upload size limit for your application running on a Nginx-PHP stack in Linux.

Two sets of file upload size limit configuration to apply for Nginx-PHP LEMP stacks

The post-obit digram is an illustration of how the browser communicates with the application server in a typical LEMP stack.

client to reverse proxy server to upstream server communication

As shown above, there are ii machines that process HTTP requests received from HTTP clients. Therefore, nosotros demand to utilise two sets of file upload size limit configuration - i for Nginx and the other for the PHP-FPM server.

Configuring file upload size limit for Nginx

Firstly, let's look at how we tin configure file upload size limit for Nginx.

Locating the Nginx configuration file

A typical installation of Nginx associates the nginx binary with the PATH variable. Therefore, you lot tin locate the Nginx configuration file past running the following command in your concluding program:

sudo nginx -t        

When I run this on my Raspberry Pi 3 running Codiad Web IDE, I got the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf exam is successful        

As can be seen, nginx reported that it is taking configurations from /etc/nginx/nginx.conf . Given that, we know where to look at for adjusting the file upload size limit for Nginx.

Configuring the file upload size limit for Nginx via client_max_body_size directive

One time you had figured out the location of the configuration file that you wish to edit, you tin and then proceed to add in the client_max_body_size directive with a value that yous desire.

This directive defines the maximum allowed size of client asking body. In addition, the default value is 1 Megabyte. When we set a value of 0 , we disable the checking of the client request torso size.

Since a file is included as the customer asking body, we will arrange the file upload size via the client_max_body_size directive.

Universal file upload size limit for HTTP requests fabricated to all upstream servers

In example you want to let a file smaller than 8 Megabytes to get through your Nginx server for all upstream servers, y'all will utilize the client_max_body_size directive inside the http block:

http {     # ...     client_max_body_size 8m;     # ... }        

Site specific file upload size limit

In case you want to apply another file upload size limit for HTTP request made to a specific upstream server, you need to await for the server cake for that site. For instance, the post-obit configuration allows whatsoever file smaller than 1 Gigabytes to pass Nginx for my Raspberry Pi 3 file sharing website:

server {          # ...          listen 443;     server_name  ps.yourdomain.com;     client_max_body_size 1024m;     # ...  }        

Uri specific file upload size limit

You can too employ the file upload size limit to a specific Uri. For case, the following configuration volition utilise a file upload size limit of 2 Gigabytes for HTTP requests sent to http://world wide web.adomain.com/upload:

server {          # ...          heed 80;     server_name  www.adomain.com;          location /upload {         # ...         client_max_body_size 2048m;         # ...     }      # ...  }        

Configuring file upload size limit for PHP FPM 7

Lastly, let's look at how to configure file upload size limit for PHP FPM seven.

Locating the php.ini configuration file

Before you continue to configure the file upload size limit for PHP FPM vii, yous need to discover the php.ini configuration file. In general, you lot can run the following command to expect for php.ini :

sudo notice / -name php.ini        

Afterward the command completes, you lot may find output similar to the following in your concluding screen:

/etc/php/7.0/fpm/php.ini /etc/php/7.0/cli/php.ini        

In this case, we volition edit /etc/php/7.0/fpm/php.ini to configure the file upload size limit for PHP FPM seven.

Configuring file upload size limit for PHP FPM 7 via upload_max_filesize and post_max_size

In guild to modify file upload size limit for PHP, we need to change ii settings - upload_max_filesize and post_max_size .

The default value for upload_max_filesize is 2 Megabytes.

The default value for post_max_size is 8 Megabytes.

Annotation that the post_max_size has to be larger than upload_max_filesize for big files.

In addition to those 2 variables, you may want to ready max_input_time to a college value for large files. In this instance, your clients will be given more than fourth dimension to upload files to your PHP FPM 7 server.

Universal file upload size limit for HTTP requests fabricated to all PHP applications served by PHP FPM 7

To apply a mutual file upload size limit for all PHP applications served past PHP FPM 7, you will edit the values for upload_max_filesize and post_max_size from /etc/php/seven.0/fpm/php.ini .

For case, if nosotros desire to modify the file upload size limit to 200 Megabytes, we will first open up /etc/php/7.0/fpm/php.ini. Later the editor loads the file, we will and so alter the lines with upload_max_filesize and post_max_size variables to the following:

upload_max_filesize = 200M post_max_size = 202M        

Application specific file upload size limit

To conform the file upload size limit for different PHP applications served by PHP FPM seven, we tin can practise and then via the ini_set role.

For instance, if we desire to modify the file upload size limit to 300 Megabytes, we will include the post-obit PHP codes in a running script:

@ini_set( 'upload_max_size' , '300M' ); @ini_set( 'post_max_size', '302M');        

Restarting Nginx and PHP FPM seven for the new file upload size limit to take consequence

In one case you lot had included the new file upload size limit for your Nginx server and PHP FPM server, restart them:

sudo systemctl restart php7.0-fpm.service sudo systemctl restart nginx.service        

After your Nginx server and PHP FPM server had restarted, the new file upload size limit will take result.

simonsheing.blogspot.com

Source: https://www.techcoil.com/blog/configuring-nginx-and-php-7-stack-in-linux-to-increase-or-decrease-file-upload-size-limit/

Post a Comment for "How to Increase Php Upload Limits in Nginx"