Redmine / Apache2上傳檔案出現 413 錯誤修復

在 Redmine 上傳檔案時, 出現 "413 Request Entity Too Large" 的錯誤訊息, 要如何解決呢?

Redmine / Apache2上傳檔案出現 413 錯誤修復

看訊息寫 Too Large, 就很直覺得往 Redmine 設定找, 設定附加檔案大小的地方, 詳見: RedmineSettings - Redmine (Redmine default setting)

Attachment max. size
Maximum size of uploaded files (in kibi-bytes). Default: 5120 (i.e. 5 mebi-bytes )

預設是 5M, 要傳的檔案才 2M, 沒道理沒辦法傳上去, 所以排除 Redmine 設定的影響.

於是在仔細看看錯誤訊息, 發現這個是 Apache 吐的錯誤訊息.

於是找 Apache 會影響相關的問題, 找到下述:

增加了 LimitRequestBody 於設定後, 還是一樣沒用 (一樣 413 Error)

再更細看看 Error Log:

  • Redmine 的 Error log: does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
  • Apache2 的 Error log: ModSecurity: Request body (Content-Length) is larger than the configured limit (131072).

原來是被 apache2 的 security module 給擋住了... 從一開始就誤看錯誤訊息....

修正 Apache2 - 413 Request Entity Too Large 步驟

  1. dpkg -L libapache2-modsecurity # 找設定檔
  2. vim /etc/modsecurity/modsecurity.conf # 修改 Request body 的大小限制, 將 131072 註解掉, 改成 5120000
    # Maximum request body size we will
    # accept for buffering
    #SecRequestBodyLimit 131072
    # 5M
    SecRequestBodyLimit 5120000
  3. sudo /etc/init.d/apache2 reload # 到此即可.

修正 Nginx -413 Request Entity Too Large 步驟

  1. vim /etc/nginx/sites-enabled/redmine.conf
  2. server { # 增加下述:client_max_body_size (上傳 size)
    client_max_body_size 5m;
    }
  3. sudo /etc/init.d/nginx reload

作者: Tsung

對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料