1、线上有个域名出现一个访问报错:
413 Payload Too Large
这里贴一下关于这个报错的解释:
The 413 (Payload Too Large) status code indicates that the server is
refusing to process a request because the request payload is larger
than the server is willing or able to process. The server MAY close
the connection to prevent the client from continuing the request.
If the condition is temporary, the server SHOULD generate a
Retry-After header field to indicate that it is temporary and after
what time the client MAY try again.
于是条件反射就去改nginx的配置,在相应的server段或location段添加client_max_body_size 100m;然后reload nginx,发现问题并没有解决。还是报错。
有google了一番,找到关于413 Payload Too Large的解释,发现应该是后端server的问题,就开始去排查后端的服务:
,发现:
Error:request entity too large
https://github.com/expressjs/body-parser#limit
应该是baody-parser,的问题:
bodyParser.json([options])
limit
Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to ‘100kb‘
默认 json limit的大小100k,我们的json已经130k了,很明显就找到问题所在了。
接下来就是修改:
app.use( bodyParser.json({limit: ‘50mb‘}) );
app.use(bodyParser.urlencoded({
limit: ‘50mb‘,
extended: true,
parameterLimit:50000
}));
2、如果报错为413 request entity too large
就应该是nginx的问题了,就需要改nginx的配置,在相应的server段或location段添加client_max_body_size 100m;然后reload nginx