茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1670802 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PI20101106_00127.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]通過設置nginx的client_max_body_size解決nginx+php上傳大文件的問題

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]通過設置nginx的client_max_body_size解決nginx+php上傳大文件的問題

通過設置nginx的client_max_body_size解決nginx+php上傳大文件的問題:


用nginx來做webserver的時,上傳大文件時需要特別注意client_max_body_size這個參數,否則會中斷在nginx的請求中,在php中是無法記錄到訪問的.
一般上傳大文件流程:
首先修改php.ini文件:
參數 設置 說明
file_uploads on 是否允許通過HTTP上傳文件的開關。默認為ON即是開
upload_tmp_dir – 文件上傳至服務器上存儲臨時文件的地方,如果沒指定就會用系統默認的臨時文件夾
upload_max_filesize 8m 望文生意,即允許上傳文件大小的最大值。默認為2M
post_max_size 8m 指通過表單POST給PHP的所能接收的最大值,包括表單裡的所有值。默認為8M
說明
一般來說,設置好上述四個參數後,在網絡正常的情況下,上傳<=8M的文件是不成問題的
但如果要上傳>8M的大文件的話,只設置上述四項還不一定能行的通。除非你的網絡真有100M/S的上傳高速,否則你還得繼續設置下面的參數。
max_execution_time 600 每個PHP頁面運行的最大時間值(秒),默認30秒
max_input_time 600 每個PHP頁面接收數據所需的最大時間,默認60秒
memory_limit 8m 每個PHP頁面所吃掉的最大內存,默認8M


但是還是不行,因為的webserver用的是nginx, google了一下,發現在nginx的conf中添加了一個參數:
默認是1M,需要增大的話。
在nginx.conf中增加一句
client_max_body_size 30m;
重啟即可

30m表示最大上傳30M,需要多大設置多大。



[root@server81 conf]# vim nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 20m;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include vhosts/*.conf;
}




原文出處: nginx的client_max_body_size解决nginx+php上传大文件的问题 - webnoties的专栏 - CSDN博客*/
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Module ngx_http_core_module
Syntax: 	client_max_body_size size;
Default:	client_max_body_size 1m;
Context: 	http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

原文出處:Module ngx_http_core_module
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Default nginx client_max_body_size
Default nginx client_max_body_size

I have been getting the nginx error:
413 Request Entity Too Large

I have been able to update my client_max_body_size in the server section of my nginx.conf file to 20M and this has fixed the issue. However, what is the default nginx client_max_body_size?



The default value for client_max_body_size directive is 1 MiB.
It can be set in http, server and location context — as in the most cases, this directive in a nested block takes precedence over the same directive in the ancestors blocks.
Excerpt from the ngx_http_core_module documentation:
    Syntax:   client_max_body_size size;
    Default:  client_max_body_size 1m;
    Context:  http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.
Don't forget to reload configuration by nginx -s reload or service nginx reload commands prepending with sudo (if any).



You can increase body size in nginx configuration file as
    sudo nano /etc/nginx/nginx.conf
    client_max_body_size 100M;

Restart nginx to apply the changes.
    sudo service nginx restart




Pooja Mane's answer worked for me, but I had to put the client_max_body_size variable inside of http section.


原文出處:Default nginx client_max_body_size - Stack Overflow
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|