Nginx 反向代理後端應用時,上傳超過 1 MB 的檔案失敗,預設 client_max_body_size 為 1 MB。
Nginx 設定遵循繼承規則:http → server → location。若在 nginx.conf 的 http 階層設定,所有 server 繼承;若在個別 server 或 location 覆寫,以最內層為準。
# 範例:針對特定虛擬主機的 location 區塊
server {
listen 80;
server_name chat.erp.example.com;
location / {
proxy_pass https://tomcat_upstream;
# 關鍵設定:允許最大 1000 MB 上傳
client_max_body_size 1000m;
# 可選:增加 proxy 讀寫逾時,防大檔上傳中斷
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
}
nginx -t # 語法檢查
nginx -s reload # 平滑重載
include domains/*; 等外部引入,實際生效設定在子檔案中。1000m = 1000 MB,1g = 1 GB,區分大小寫。maxPostSize、Spring Boot 需 spring.servlet.multipart.max-file-size、PHP 需 upload_max_filesize 等。# 使用 curl 測試 10 MB 檔案上傳
dd if=/dev/zero of=10mb.bin bs=1M count=10
curl -X POST -F "file=@10mb.bin" https://chat.erp.example.com/upload
若回傳 200 且後端收到完整檔案,即設定生效。