sunmaobin.github.io icon indicating copy to clipboard operation
sunmaobin.github.io copied to clipboard

经验分享-解决Ngxin和Node环境下 Runtime Error : 413,request entity too large

Open sunmaobin opened this issue 6 years ago • 0 comments

背景

我们服务端使用Nginx+Node(Express v4.15.2)部署,今天遇到Post参数过长时请求报错:

Runtime Error : 413,request entity too large

为什么会过长呢?因为有一个变态的需求,就是需要将图片读出来BASE64作为参数传递,所以...

解决

  • 修改Nginx配置,一般路径如下:
vi /etc/nginx/conf.d/default.conf

在路由接口上增加2个参数,如下:

location /api/ {
       client_max_body_size 0;
       proxy_buffering off;
       proxy_pass http://localhost:8000/;
}

然后reload一下Ngxin的服务:

/usr/sbin/nginx -s reload
  • 修改Express服务中,app.js 文件,修改2个参数,如下(假如参数限制50M):
app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));

sunmaobin avatar Mar 21 '19 13:03 sunmaobin