Home 解决Http Code 413(Request Entity Too Large) 错误
Post
Cancel

解决Http Code 413(Request Entity Too Large) 错误

Fix 413 Request Entity Too Large

Ingress:

1
2
3
4
5
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 10m

Spring Boot:

1
2
3
4
5
6
server:
  servlet:
    multipart:
      enabled: true
      max-file-size: 50MB
      max-request-size: 300MB

Spring Cloud Gateway:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Component
public class NettyConfig implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {

    /**
     * 10m
     */
    @Value("${server.max-initial-line-length:10485760}")
    private int maxInitialLingLength;

    @Override
    public void customize(final NettyReactiveWebServerFactory factory) {
        factory.addServerCustomizers(httpServer -> httpServer.httpRequestDecoder(httpRequestDecoderSpec -> {
             httpRequestDecoderSpec.maxInitialLineLength(maxInitialLingLength);
            return httpRequestDecoderSpec;
            }
        ));
    }
}

weixin.png

公众号名称:怪味Coding
微信扫码关注或搜索公众号名称
This post is licensed under CC BY 4.0 by the author.