Nginx 預設限制上傳檔案大小為 1MB,超過會回傳 413 Request Entity Too Large。本文記錄調整 client_max_body_size 的正確位置與重新載入步驟,避免設定不生效的常見坑點。
nginx.conf 的 server 區塊加入 client_max_body_size 1000m; 重啟無效。主設定檔包含 include domains/*;,實際虛擬主機設定在獨立檔案(如 domains/chat.erp.360buy.com)。client_max_body_size 必須設在**具體處理請求的 location 或 server 區塊**中,才會生效。
# domains/chat.erp.360buy.com
server {
listen 80;
server_name chat.erp.360buy.com;
location / {
proxy_pass https://tomcat;
client_max_body_size 1000m; # 這裡才有效!
}
}
# 語法檢查
/export/servers/nginx/sbin/nginx -t
# 平滑重載
/export/servers/nginx/sbin/nginx -s reload
client_max_body_size 可設於 http、server、location 三層,**越內層優先級越高**。location / 區塊。k、m、g,0 代表不限制。maxPostSize 或 Spring multipart.maxFileSize 設定。設定完成並 reload 後,大檔上傳即恢復正常,無需重啟 Nginx 主進程。