PHP and Nginx file upload size limit issue

王林
Release: 2023-04-07 18:44:01
Original
2163 people have browsed it

PHP and Nginx file upload size limit issue

PHP large file uploads occupy a lot of resources, so the upload size needs to be limited. The following are the three relevant parameters:

client_max_body_size
upload_max_filesize
post_max_size
Copy after login

For some nginx php websites , the size of the uploaded file will be limited by many aspects. One is the limitation of nginx itself, which limits the size of the file uploaded by the client. The other is the default settings in multiple places in the php.ini file.

So in order to solve the problem of uploading file size limit, many modifications must be made. A few places are listed below.

Solution:

1. Modify the /usr/local/nginx/conf/nginx.conf file, find client_max_body_size and set the following value to what you want. value. For example:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
     # 
     location ~ \.php$ { 
       root      /home/www/htdocs; 
       fastcgi_pass  127.0.0.1:9000; 
       fastcgi_index index.php; 
       fastcgi_param SCRIPT_FILENAME /home/www/htdocs$fastcgi_script_name; 
       include    fastcgi_params; 
   
       client_max_body_size 35m;    #客户端上传文件大小设为35M 
       client_body_temp_path /home/www/nginx_temp;    #设置临时目录 
     }
Copy after login

2. Modify the php.ini file

upload_max_filesize = 8M  
post_max_size = 10M  
memory_limit = 20M 
max_execution_time=300 
file_uploads = On #默认允许HTTP文件上传,此选项不能设置为OFF。
upload_tmp_dir =/tmp/www
Copy after login

When uploading large files, you will feel that the upload speed is slow. When it exceeds a certain time, it will report that the script execution exceeds 30 The second error is due to the max_execution_time configuration option in the php.ini configuration file. It indicates the maximum allowed execution time (seconds) of each script, and 0 indicates no limit. You can adjust the value of max_execution_time appropriately. Setting it to 0 is not recommended.

Recommended tutorial: PHP video tutorial

The above is the detailed content of PHP and Nginx file upload size limit issue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template