默认 nginx client_max_body_size

Default nginx client_max_body_size

我一直收到 nginx 错误:

413 Request Entity Too Large

我已经能够将 nginx.conf 文件的服务器部分中的 client_max_body_size 更新为 20M,这已解决问题。但是,默认的nginx是什么client_max_body_size?

client_max_body_size 指令的默认值为 1 MiB

它可以在 httpserverlocation 上下文中设置 — 与在 中一样 嵌套块中的此 指令优先于祖先块中的相同指令 .

摘自ngx_http_core_module documentation

Syntax:   client_max_body_size size;
Default:  client_max_body_size 1m;
Context:  http, server, location

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

别忘了reload configuration 通过 nginx -s reloadservice nginx reload 命令加上 sudo(如果有的话)。

您可以在 nginx 配置文件中增加正文大小,如

sudo nano /etc/nginx/nginx.conf

client_max_body_size 100M;

重新启动 nginx 以应用更改。

sudo service nginx restart

Pooja Mane 的回答对我有用,但我必须将 client_max_body_size 变量放在 http 部分中。

您必须在 nginx.conf 文件中增加 client_max_body_size。这是基本步骤。但是,如果您的后端 laravel 那么您还必须在 php.ini 文件中进行一些更改。这取决于你的后端。下面我提到了文件位置和条件名称。

sudo vim /etc/nginx/nginx.conf.

打开文件后将其添加到 HTTP 部分。

client_max_body_size 100M;

Nginx client_max_body_size 的默认值是 1MB

您可以通过三种不同的方式更新此值

1。在影响所有服务器块(虚拟主机)的 http 块中设置。

http {
    ...
    client_max_body_size 100M;
}

2。在 server 块中设置,影响特定的 site/app.

server {
    ...
    client_max_body_size 100M;
}

3。在 location 块中设置,影响 site/app.

下的特定目录(上传)
location /uploads {
    ...
    client_max_body_size 100M;
}

了解更多信息click here

这适用于新的 AWS Linux 2 环境。要解决此问题 - 您需要包装您的配置文件。如果您使用 Docker,您应该有一个包含您的 Dockerrun.aws.json 的 zip 文件(我的文件名为 deploy.zip)。如果你不这样做 - 它很容易修改,只需通过压缩你的部署 zip -r deploy.zip Dockerrun.aws.json

这样 - 您现在需要添加一个 .platform 文件夹,如下所示:

APP ROOT
├── Dockerfile
├── Dockerrun.aws.json
├── .platform
│   └── nginx
│       └── conf.d
│           └── custom.conf

您可以随意命名您的 custom.conf,并且可以拥有任意数量的文件。在 custom.conf 中,您只需将以下内容放入

client_max_body_size 50M;

或者您想要的任何配置。这样-将您的 zip 修改为

zip -r deploy.zip Dockerrun.aws.json .platform

并部署。您的 Nginx 服务器现在将遵守新命令

此处有更多详细信息:https://blog.benthem.io/2022/04/05/modifying-nginx-settings-on-elasticbeanstalk-with-docker.html