我想在 NGINX 組態中自訂「client_max_body_size」值,以便將大型檔案上傳到 AWS Elastic Beanstalk 環境。
解決方法
NGINX 預設的檔案上傳限制為 1 MB。若要上傳大於 1 MB 的檔案,請更新 client_max_body_size 值。
**重要事項:**M 和 MB 都是「megabyte」的等效表達方式。例如,2M 等於 2 MB。但是,NGINX 組態只接受「M」作為有效的語法值。數字與字母「M」之間不留空格。
注意事項: 若要為所有 Amazon Linux 2 和 Amazon Linux 2023 平台版本自訂預設 Proxy 組態,請參閱擴充 Elastic Beanstalk Linux 平台。
若要在 Amazon Linux 2 和 Amazon Linux 2023 中設定 client_max_body_size 值,請完成以下步驟:
-
建立名為 client_max_body_size.conf 的 .conf 組態檔,其中包含以下內容:
client_max_body_size 50M;
-
將 .conf 檔案 client_max_body_size.conf 複製到應用程式來源套件中名為 .platform/nginx/conf.d/ 的資料夾。
注意事項: Elastic Beanstalk NGINX 組態會自動納入 .platform 資料夾中的 .conf 檔案。如果來源套件中沒有 .conf 檔案,請務必建立此路徑。
以下範例顯示了 Java SE 平台上應用程式 zip 檔案中 .platform 目錄與 .conf 檔案的結構。對於所有 Linux 平台,.platform 資料夾都必須放在應用程式來源套件的根目錄中。如需封裝應用程式的詳細資訊,請參閱您平台的文件。
~/my-app.zip/
|-- web.jar
|-- Procfile
|-- readme.md
`-- .platform/
|-- nginx/ # Proxy configuration
| `-- conf.d/
| `-- client_max_body_size.conf
- 在您的 Elastic Beanstalk 環境中部署新的應用程式版本。
- 使用 SSH 登入在 Elastic Beanstalk 環境中執行的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。
- 若要驗證 NGINX 組態語法是否正確,以及對 client_max_body_size 值所做的變更是否已套用,請執行下列命令。
$ sudo nginx -T | egrep -i "client_max_body_size"
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
client_max_body_size 50M;
相關資訊
建立應用程式來源套件