[英]Default nginx client_max_body_size
I have been getting the nginx error:我一直收到 nginx 错误:
413 Request Entity Too Large
I have been able to update my client_max_body_size
in the server section of my nginx.conf file to 20M and this has fixed the issue.我已经能够将我的 nginx.conf 文件的服务器部分中的client_max_body_size
更新为 20M,这已经解决了这个问题。 However, what is the default nginx client_max_body_size
?但是,默认的 nginx client_max_body_size
是多少?
The default value for client_max_body_size
directive is 1 MiB . client_max_body_size
指令的默认值为1 MiB 。
It can be set in http
, server
and location
context — as in the most cases , this directive in a nested block takes precedence over the same directive in the ancestors blocks .它可以在http
、 server
和location
上下文中设置——在大多数情况下,嵌套块中的这个指令优先于祖先块中的相同指令。
Excerpt from the ngx_http_core_module documentation :摘自ngx_http_core_module 文档:
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.设置客户端请求正文的最大允许大小,在“Content-Length”请求标头字段中指定。 If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.如果请求中的大小超过配置值,则向客户端返回 413(请求实体太大)错误。 Please be aware that browsers cannot correctly display this error.请注意,浏览器无法正确显示此错误。 Setting size to 0 disables checking of client request body size.将 size 设置为 0 将禁用对客户端请求正文大小的检查。
Don't forget to reload configuration by nginx -s reload
or service nginx reload
commands prepending with sudo
(if any).不要忘记通过nginx -s reload
或service nginx reload
命令重新加载配置,并在前面加上sudo
(如果有)。
You can increase body size in nginx configuration file as您可以在 nginx 配置文件中增加 body 大小作为
sudo nano /etc/nginx/nginx.conf须藤纳米 /etc/nginx/nginx.conf
client_max_body_size 100M; client_max_body_size 100M;
Restart nginx to apply the changes.重新启动 nginx 以应用更改。
sudo service nginx restart须藤服务 nginx 重启
Nginx default value for client_max_body_size
is 1MB
client_max_body_size
Nginx默认值为1MB
You can update this value by three different way您可以通过三种不同的方式更新此值
http
block which affects all server blocks (virtual hosts). 1.设置在影响所有服务器块(虚拟主机)的http
块中。http {
...
client_max_body_size 100M;
}
server
block, which affects a particular site/app. 2. 在server
块中设置,这会影响特定站点/应用程序。server {
...
client_max_body_size 100M;
}
location
block, which affects a particular directory (uploads) under a site/app. 3.在location
块中设置,这会影响站点/应用程序下的特定目录(上传)。location /uploads {
...
client_max_body_size 100M;
}
For more info click here欲了解更多信息,请单击此处
This works for the new AWS Linux 2 environment.这适用于新的 AWS Linux 2 环境。 To fix this - you need to wrap your configuration file.要解决此问题 - 您需要包装您的配置文件。 You should have, if you're using Docker, a zip file (mine is called deploy.zip
) that contains your Dockerrun.aws.json
.如果您使用的是 Docker,则应该有一个 zip 文件(我的文件名为deploy.zip
),其中包含您的Dockerrun.aws.json
。 If you don't - it's rather easy to modify, just zip your deploy via zip -r deploy.zip Dockerrun.aws.json
如果你不这样做 - 它很容易修改,只需 zip 你的部署通过zip -r deploy.zip Dockerrun.aws.json
With that - you now need to add a .platform
folder as follows:有了它 - 您现在需要添加一个.platform
文件夹,如下所示:
APP ROOT
├── Dockerfile
├── Dockerrun.aws.json
├── .platform
│ └── nginx
│ └── conf.d
│ └── custom.conf
You can name your custom.conf
whatever you want, and can have as many files as you want.您可以随意命名您的custom.conf
,并且可以拥有任意数量的文件。 Inside custom.conf
, you simply need to place the following inside在custom.conf
中,您只需将以下内容放入其中
client_max_body_size 50M;
Or whatever you want for your config.或者你想要的任何配置。 With that - modify your zip to now be这样-将您的 zip 修改为现在
zip -r deploy.zip Dockerrun.aws.json.platform
And deploy.并部署。 Your Nginx server will now respect the new command您的 Nginx 服务器现在将遵守新命令
More details here: https://blog.benthem.io/2022/04/05/modifying-nginx-settings-on-elasticbeanstalk-with-docker.html更多细节在这里: https://blog.benthem.io/2022/04/05/modifying-nginx-settings-on-elasticbeanstalk-with-docker.html
You have to increase client_max_body_size in nginx.conf
file.您必须在nginx.conf
文件中增加 client_max_body_size。 This is the basic step.这是基本步骤。 But if your backend laravel
then you have to do some changes in the php.ini
file as well.但是如果你的后端laravel
那么你也必须在php.ini
文件中做一些改变。 It depends on your backend.这取决于你的后端。 Below I mentioned file location and condition name.下面我提到了文件位置和条件名称。
sudo vim /etc/nginx/nginx.conf.
After open the file adds this into HTTP section.打开文件后,将其添加到 HTTP 部分。
client_max_body_size 100M;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.