問題描述
如何增加 nginx.conf 中的 client_max_body_size? (How do you increase the client_max_body_size in nginx.conf?)
我在本地 ddev 實例中上傳大文件時收到“413 Request Entity Too Large”錯誤,特別是使用備份和遷移從大型數據庫文件恢復時。
我正在使用 ddev 1.5.1、PHP 7.1、nginx 1.15.3 和 Drupal 7.60。我試過提供一個自定義的 nginx 配置,就像它在文檔中所說的那樣,但我試過的都沒有奏效。通過谷歌搜索,我認為問題在於 client_max_body_size 太低,但我試圖將該值加倍,但沒有任何效果。我複制了 d7 配置並添加到 client_max_body_size 行並重新啟動項目,但仍然出現錯誤。
參考解法
方法 1:
First, for this issue you really don't want to be using backup_migrate for a restore, especially for a 100MB upload, which is way huge. ddev import‑db
happily accepts your backup_migrate *.mysql.gz file, and is ever‑so‑much faster and doesn't require custom config. ddev import‑db ‑‑src=/path/to/my‑backup‑migrate.mysql.gz
But to do it the way you're trying to do you have to both override nginx‑site.conf AND php.
In your .ddev/nginx‑site.conf in the "server" section, add client_max_body_size 1000M;
if you want to bump it to 1GB. (See nginx custom config in docs.
In .ddev/php/bigpost.ini (name is arbitrary, see docs), you'll want:
post_max_size = 1000M
upload_max_filesize = 1000M
Then ddev rm
and ddev start
and you should see the upload size improved.
方法 2:
I ran into the same issue today when trying to debug some long running TUS file uploads. Apparently the problem is not necessarily with the ddev web container but with the nginx ddev‑router container. Here the request size is also limited to 100m (client_max_body_size 100m).
You can temporarily bypass this issue in by taking following steps: ‑ ssh into ddev‑router container ‑ edit /app/nginx.tmpl and set a higher client max_body_size ‑ restart router container
This works until you remove all ddev containers (or remove the last active ddev project).
(by Jake Ineichen、rfay、Robert Lang)