Nginx 413 Request Entity Too Large错误解决
Request Body Size Limit (官方文章)
When a client is uploading data, such as form fields, static files, or API payloads through an HTTP connection, all of this data is sent in the request body part of the HTTP request. The length of the request body should be defined in a Content-Length
header.
当客户端通过HTTP连接上传诸如表单字段,静态文件或API之类的数据时,所有这些数据都在HTTP请求的请求体部分中发送。请求主体的长度应在Content-Length
标头中定义
When the request body is larger than the allowed value, NGINX Unit responds with HTTP code 413
(Payload
Too
Large)
.
当请求主体大于允许值时,NGINX单元以HTTP代码响应413
(Payload
Too
Large)
。
This configuration parameter has the same meaning as the NGINX directive client_max_body_size
. When you limit the request body size in NGINX Unit, make sure that your NGINX reverse proxy and load balancers are configured appropriately.
此配置参数与NGINX指令具有相同的含义client_max_body_size
。当您限制NGINX单元中的请求包体大小时,请确保正确配置了NGINX反向代理和负载均衡。
Syntax: | client_max_body_size |
---|---|
Default: | |
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.
设置客户端请求正文的最大允许大小,在“ Content-Length”请求标头字段中指定。如果请求中的大小超过配置的值,则会向客户端返回413(请求实体太大)错误。请注意,浏览器无法正确显示此错误。
HTTP 状态码
413:用户上传的文件过大,需要调高 client_max_body_size 参数设置
Nginx出现的413 Request Entity Too Large错误,这个错误一般在上传文件的时候出现,打开nginx主配置文件nginx conf,找到http{}段,解决方法就是打开nginx主配置文件nginx.conf添加:client_max_body_size nM;
在文件上传时,如果上传文件比较大会出现报错:Status Code: 413 Request Entity Too Large,此时的响应头信息详细示例如下:
Request Method: POST
Status Code: 413 Request Entity Too Large
Remote Address: 10.147.26.139:80
Referrer Policy: no-referrer-when-downgrade
这正是超过了nginx配置的上传文件大小限制导致的。配置项即是client_max_body_size size,其默认大小为1M,详细文档说明:client_max_body_size 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. 在视频上传网站,此项配置我们可以设置为1G以上,按需配置:client_max_body_size 2048M;
日志:包括nginx proxy以及nginx web上都有413错误记录:
2020/05/09 15:28:06 [error] 2705932#0: *3448 client intended to send too large body: 302491285 bytes, POST /uploadfile?fileName
2020/05/09 15:28:06 [error] 8#8: *4949 client intended to send too large body: 302491285 bytes, client: 15.17.2.19
最后,虽然nginx上的配置修改了,但是nginx后端的服务也需要进行相应修改,比如后端php的话就需要修改post_max_size,memory_limit,upload_max_filesize三项配置值:建议memory_limit的值比上传文件的大小值大点,因为memory_limit除了上传的文件外还有其它程序等所占用空间,不然实际可上传的文件大小肯定不到2048M。
post_max_size = 2048M
memory_limit = 2248M
upload_max_filesize = 2048M
相关文章
- Nginx配置文件_nginx.conf
- linux出现e325错误,centos系统使用VI访问文件时候出现E325: ATTENTION类的错误提示处理方法…[通俗易懂]
- Spring 项目启动测试的时候错误:Unable to acquire JDBC Connection
- Nginx 的配置文件 nginx.conf
- 图文结合带你搞懂MySQL日志之Error Log(错误日志)
- 自定义 WordPress 数据库错误页
- Nginx服务器常见错误和解决办法
- iis7上常见的php错误提示有哪些
- nginx+tomcat报504超时错误详解程序员
- 状态Linux查看Nginx服务状态的简单方法(linux查看nginx)
- 情况Linux下查看Nginx进程状态:一招即通(linux查看nginx进程)
- 日志Linux删除Nginx日志:简易清理方式(linux删除nginx)
- 缓存Linux删除Nginx缓存:轻松解决一个困难(linux删除nginx)
- 日志解决Linux系统中Nginx删除日志的方法(linux删除nginx)
- Linux下Nginx实现快速高效的网络服务(linux的nginx)
- Nginx网站架构实战——03、nginx虚拟主机配置
- Nginx网站架构实战——02、nginx信号量
- Nginx主配置文件nginx.conf详解
- 《Nginx官方文档》控制nginx
- 《Nginx官方文档》如何安装nginx
- 罪魁查找 Linux 下段错误的罪魁!(linux定位段错误的是)
- 健康码申请遭遇Redis错误(健康码申请redis错误)
- 借助Redis和Nginx进行更有效的负载均衡(redis配合nginx)
- 解决Nginx+PHP(FastCGI)遇到的502BadGateway错误
- Win7IIS7.5运行ASP时出现500错误的解决办法
- nginx加php-fpm出现502badgateway错误的5种解决方法
- nginx服务器access日志中大量400badrequest错误的解决方法