【Nginx】解决413错误

项目在尝试通过接口上传Excel文件时遇到413错误,这是由于nginx配置中client_max_body_size默认限制为1MB,超过了此限制的请求将被拒绝。日志显示客户端试图发送的数据大小远超限制。解决方案是调整nginx配置文件,增大允许的最大请求体大小,例如设置为20M。完成修改后,需重启nginx服务使配置生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目场景:

接收Excel文件


问题描述

调用该接口时发生413错误

接口服务nginx日志

2022/09/09 07:02:18 [error] 10#10: *6 client intended to send too large body: 3501022 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=p3cNGR&timestamp=1662678138.514602 HTTP/1.1", host: "10.11.206.141:3121"
2022/09/09 07:02:23 [error] 10#10: *7 client intended to send too large body: 3501022 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=p3cNGR&timestamp=1662678138.514602 HTTP/1.1", host: "10.11.206.141:3121"
2022/09/09 07:02:28 [error] 10#10: *8 client intended to send too large body: 3501022 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=p3cNGR&timestamp=1662678138.514602 HTTP/1.1", host: "10.11.206.141:3121"
2022/09/09 08:23:15 [error] 10#10: *13 client intended to send too large body: 3432243 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=pszvLM&timestamp=1662682994.933834 HTTP/1.1", host: "10.11.206.141:3121"
2022/09/09 08:23:20 [error] 10#10: *14 client intended to send too large body: 3432243 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=pszvLM&timestamp=1662682994.933834 HTTP/1.1", host: "10.11.206.141:3121"
2022/09/09 08:23:25 [error] 10#10: *15 client intended to send too large body: 3432243 bytes, client: 192.168.7.1, server: data-dispatch-center, request: "POST /api/v1/app/form/excel_import?nonce=pszvLM&timestamp=1662682994.933834 HTTP/1.1", host: "10.11.206.141:3121"

原因分析:

众所周知,413含义是“Request Entity Too Large”
nginx 配置文件中的client_max_body_size是控制请求body的大小限制的参数,默认为1MB,如果超过这个数值,则会直接返回413状态码
在这里插入图片描述


解决方案:

修改nginx配置文件

http {
    ...
    client_max_body_size 20M;
}  

参考:
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
https://stackoverflow.com/a/62985236

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值