對於nginx+php的一些網站,上傳檔案大小會受到多個方面的限制,一個是nginx本身的限制,限制了用戶端上傳檔案的大小,一個是php.ini檔案中預設了多個地方的設定。所以為瞭解決上傳檔案大小限定的問題必須要做出多處修改。以下整理了幾個地方。
1、修改/usr/local/nginx/conf/nginx.conf 檔案,尋找 client_max_body_size 將後面的值設定為你想設定的值。比如:view plainprint?
- # 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; #設定臨時目錄
- }
附錄:Nginx有一個Upload組件:
上傳速率,上傳Body大小,也就是上傳檔案時可能較大?
client_max_body_size 1024M
upload_limit_rate 158k
如下:view plainprint?
- location /upload {
- upload_pass /up.php;
- upload_cleanup 400 404 499 500-505;
- #upload_store /data/app/test.local/upload_tmp;
- upload_store /tmp;
- upload_store_access user:r;
- client_max_body_size 1024M;
- upload_limit_rate 158k;
- upload_set_form_field "${upload_field_name}_name" $upload_file_name;
- upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
- upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;
- upload_aggregate_form_field "${upload_field_name}_md5" $upload_file_md5;
- upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;
- upload_pass_form_field "^.*$";
- #upload_pass_form_field "^pid$|^tags$|^categoryid$|^title$|^userid$|^user_id$|^is_original$|^upload_file_name$|^upload_file_content_type$|^upload_file_path$|^upload_file_md5$|^upload_file_size$";
- }
2、修改php.ini
在php.ini裡面查看如下行:
- 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
在上傳大檔案時,你會有上傳速度慢的感覺,當超過一定的時間,會報指令碼執行超過30秒的錯誤,這是因為在php.ini設定檔中max_execution_time配置選項在作怪,其表示每個指令碼最大允許執行時間(秒),0 表示沒有限制。你可以適當調整max_execution_time的值,不推薦設定為0。
參考文章:
PHP.INI配置:檔案上傳功能配置教程:http://www.leapsoul.cn/?p=488