問題描述:
上傳檔案失敗,檔案大小約4M。上傳程式為Java,透過nginx反向代理寫入Fastdfs中,但一直失敗,查看nginx錯誤日誌,提示如下內容:
client intended to send too large body: 4134591 bytes
(相關推薦:nginx教學)
分析:
根據錯誤訊息提示,客戶端發送的body過大,nginx預設的客戶端body大小為1M。
官方文件如下:
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.
解決方法:
根據官方文件說明,可以在nginx設定檔中http、server、location等設定區塊新增配置,client_max_body_size size ;來調整允許的客戶端上傳檔案的body大小。設定為0,表示不限制。
程式碼範例:
http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; client_max_body_size 100m; .... }
以上是nginx上傳檔案失敗,提示上傳檔案過大,怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!