Nginx服务出现413 Request Entity Too Large的解决办法

背景

Nginx服务器上运行基于SrpingBoot的WebApi服务(服务端已设置最大可上传50M),通过前端上传一个超过10M的文件,出现以下提示:
在这里插入图片描述

原因分析

查看Nginx 关于client_max_body_size的描述
http服务客户端最大上传默认设置为1M

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.

解决办法

修改nginx.conf配置文件,增加client_max_body_size大小。

http {
 	...
 	# set client body size to 50M #
    client_max_body_size 50m;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    ...
    }

测试

上传13M的文档
在这里插入图片描述
上传成功
在这里插入图片描述

原创文章 56 获赞 8 访问量 4732

猜你喜欢

转载自blog.csdn.net/jpgzhu/article/details/105674685
今日推荐