v2to
v2to

Reputation: 529

Nginx Ingress returns 413 Entity Too Large

on my Cluster, I'm trying to upload a big file but when I try, I get the 413 Error

error parsing HTTP 413 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>413 Request Entity Too Large</title></head>\r\n<body>\r\n<center><h1>413 Request Entity Too Large</h1></center>\r\n<hr><center>nginx/1.19.3</center>\r\n</body>\r\n</html>\r\n"

I know that this is caused by a default parameter of nginx and I need to override it. On the documentation I've found that this can be done using two ways:

  1. using annotation on ingress config
  2. using a configMap

I have tried both ways with no result.

Here are my yaml: ingress.yml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "700m"
  name: nginx-ingress
spec:
  rules:
    - host: example.com
      http:
        paths:
          - backend:
              serviceName: nginx-service
              servicePort: 80
            path: /              

and configmap.yml:

apiVersion: v1
data:
  proxy-body-size: "800m"
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  labels:
    app.kubernetes.io/name: nginx-ingress
    app.kubernetes.io/part-of: nginx-ingress

Upvotes: 27

Views: 51462

Answers (8)

rafaelnaskar
rafaelnaskar

Reputation: 783

For future searches, It works for me:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
  name: docker-registry
  namespace: docker-registry
spec:

Upvotes: 28

Manishkumar Ranipa
Manishkumar Ranipa

Reputation: 21

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
    nginx.org/proxy_read_timeout: "720s"
    nginx.ingress.kubernetes.io/proxy-body-size: "0"

Above settings work for me on AKS nginx. Zero means no limit and if user want to apply upload limit, just replace 0 with desired limit like 150m.

Upvotes: 2

Utkarsh Sharma
Utkarsh Sharma

Reputation: 403

Below configurations worked out for me:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: cs-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/proxy-body-size: 16m

reference: https://github.com/kubernetes/ingress-nginx/issues/4825

Upvotes: 3

Toni
Toni

Reputation: 1354

There are some good answers here already to avoid that 413.

As for example editing the Ingress (better redeploying) with the following annotations:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"

Furthermore, for NGINX an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter client_max_body_size reference.

Upvotes: 4

Rafiq
Rafiq

Reputation: 11515

For NGINX, an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter

To configure this setting globally for all Ingress rules, the proxy-body-size value may be set in the NGINX ConfigMap. To use custom values in an Ingress rule define these annotation:

nginx.ingress.kubernetes.io/proxy-body-size: 8m

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-max-body-size

for node.js you might set

app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ limit: '50mb' }));

Upvotes: 15

Michael A.
Michael A.

Reputation: 1209

Maybe my experience will help somebody. All my settings were Ok in nginx, but nginx stood behind CloudFlare in Proxy mode. So try to set it to "DNS only" in order to make sure there is nothing between you and nginx.

enter image description here

Upvotes: 1

Thiago G. Alves
Thiago G. Alves

Reputation: 1409

I was with the same problem using Nginx Ingress on GKE.

These are the annotations that worked for me:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/client-max-body-size: "0"
    nginx.org/proxy-connect-timeout: 600s
    nginx.org/proxy-read-timeout: 600s

Don't forget to put the correct values for you.

For more details you can see these docs:

  1. Using Annotations
  2. Client Max Body Size

PS I've installed my "Nginx Ingress Controller" following this tutorial.

Upvotes: 6

Wytrzymały Wiktor
Wytrzymały Wiktor

Reputation: 13888

There are few things to have in mind while setting this up:

  1. It is better to recreate the Ingress object rather than edit it to make sure that the configuration will be loaded correctly. Delete the Ingress and recreate it again with the proper annotations.

  2. If that's still not working you can try to use the ConfigMap approach, for example:


apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
  namespace: ingress-nginx
  labels:
    app: ingress-nginx
data:
  proxy-body-size: "8m"
  1. Notice that setting size to 0 disables checking of client request body size.

  2. Remember to set the value greater than the size of data that you are trying to push.

  3. Use the proper apiVersion based on your Kubernetes version. Notice that:

The extensions/v1beta1 and networking.k8s.io/v1beta1 API versions of Ingress will no longer be served in v1.22.

  • Migrate manifests and API clients to use the networking.k8s.io/v1 API version, available since v1.19.

  • All existing persisted objects are accessible via the new API

Upvotes: 2

Related Questions