nginx上傳文件失敗,提示上傳文件過大,怎么解決

nginx上傳文件失敗,提示上傳文件過大,怎么解決

問題描述:

上傳文件失敗,文件大小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; 	.... 	}

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊5 分享