web 服务中上传文件大小控制

参考文章:https://rensanning.iteye.com/blog/2388353

项目场景:

Vue + Nginx + Java + Tomcat 

Nginx作为反向代理服务器,访问Tomcat中的后端项目。

问题:

项目需求将上传20M限制提高到20M,将web.xml中的multipart-config参数设置修改成20M之后,仍然不生效。

请求返回的一直都是413 (Request Entity Too Large) 

<multipart-config>  
    <location>/tmp</location>  
    <max-file-size>5242880</max-file-size>  
    <max-request-size>10485760</max-request-size>  
    <file-size-threshold>32768</file-size-threshold>  
</multipart-config>  

这里就需要改到下面这个参数:

Nginx:client_max_body_size(ngnix.conf)

server {  
  
    client_max_body_size 1m;  //默认大小为1M
  
    location /users/profile/edit/avatar {  
        client_max_body_size 2m;  //对特定的路径单独指定大小
    }  
  
    location /users/profile/edit/images {  
        client_max_body_size 5m;  
    }  
  
}  

 

默认是1MB,超过后直接返回413 (Request Entity Too Large) 。设置为0时表示无限制。

 

posted @ 2019-08-18 13:55  超级珍贵  阅读(975)  评论(0编辑  收藏  举报