Nginx 入口错误 413 请求实体太大

发布于 2025-01-10 17:32:52 字数 2261 浏览 0 评论 0原文

我将 ingress-nginx 与 Helm Chart 结合使用。我曾经遇到过一个问题,当我上传文件(50MB)时,我会收到错误 413 Request Entity Too Large nginx。

因此,我将 value.yaml 文件中的 proxy-body-size 值更改为 150m,所以我现在应该能够上传我的文件。 但现在我收到错误“413 Request Entity Too Large openresty/1.13.6.2”。 我检查了入口控制器上的 nginx.conf 文件,client_max_body_size 的值已正确设置为 150m。

经过一番研究,我发现nginx中的lua模块使用了openresty。 有谁知道我如何为 openresty 设置此设置,或者我缺少什么参数?

我当前的配置如下:

values.yml:

ingress-nginx:
  defaultBackend:
    nodeSelector:
      beta.kubernetes.io/os: linux
  controller:
    replicaCount: 2
    resources:
      requests:
        cpu: 1
        memory: 4Gi
      limits:
        cpu: 2
        memory: 7Gi
    autoscaling:
      enabled: true
      minReplicas: 2
      maxReplicas: 10
      targetCPUUtilizationPercentage: 90
      targetMemoryUtilizationPercentage: 90
    ingressClassResource:
      name: nginx
      controllerValue: "k8s.io/nginx"
    nodeSelector:
      beta.kubernetes.io/os: linux
    admissionWebhooks:
      enabled: false
      patch:
        nodeSelector:
          beta.kubernetes.io/os: linux
    extraArgs:
      ingress-class: "nginx"
    config:
      proxy-buffer-size: "16k"
      proxy-body-size: "150m"
      client-body-buffer-size: "128k"
      large-client-header-buffers: "4 32k"
      ssl-redirect: "false"
      use-forwarded-headers: "true"
      compute-full-forwarded-for: "true"
      use-proxy-protocol: "false"

ingress.yml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  namespace: namespacename
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
    nginx.ingress.kubernetes.io/proxy-buffers-number: "8"
    nginx.ingress.kubernetes.io/client-body-buffer-size: "128k"
    nginx.ingress.kubernetes.io/proxy-body-size: "150m"
spec:
  tls:
    - hosts:
        - hostname
  rules:
    - host: hostname
      http:
        paths:
          - path: /assets/static/
            pathType: ImplementationSpecific
            backend:
              service:
                name: servicename
                port:
                  number: 8080

I use ingress-nginx with Helm Chart. I used to have the problem, that when I would upload a file (50MB) that I would get the error 413 Request Entity Too Large nginx.

So I changed the proxy-body-size value in my values.yaml file to 150m, so I should now be able to upload my file.
But now I get the error "413 Request Entity Too Large openresty/1.13.6.2".
I checked the nginx.conf file on the ingress controller and the value for client_max_body_size is correctly set to 150m.

After some research I found out that openresty is used by the lua module in nginx.
Does anybody know how I can set this setting too for openresty, or what parameter I am missing ?

My current config is the following:

values.yml:

ingress-nginx:
  defaultBackend:
    nodeSelector:
      beta.kubernetes.io/os: linux
  controller:
    replicaCount: 2
    resources:
      requests:
        cpu: 1
        memory: 4Gi
      limits:
        cpu: 2
        memory: 7Gi
    autoscaling:
      enabled: true
      minReplicas: 2
      maxReplicas: 10
      targetCPUUtilizationPercentage: 90
      targetMemoryUtilizationPercentage: 90
    ingressClassResource:
      name: nginx
      controllerValue: "k8s.io/nginx"
    nodeSelector:
      beta.kubernetes.io/os: linux
    admissionWebhooks:
      enabled: false
      patch:
        nodeSelector:
          beta.kubernetes.io/os: linux
    extraArgs:
      ingress-class: "nginx"
    config:
      proxy-buffer-size: "16k"
      proxy-body-size: "150m"
      client-body-buffer-size: "128k"
      large-client-header-buffers: "4 32k"
      ssl-redirect: "false"
      use-forwarded-headers: "true"
      compute-full-forwarded-for: "true"
      use-proxy-protocol: "false"

ingress.yml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  namespace: namespacename
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
    nginx.ingress.kubernetes.io/proxy-buffers-number: "8"
    nginx.ingress.kubernetes.io/client-body-buffer-size: "128k"
    nginx.ingress.kubernetes.io/proxy-body-size: "150m"
spec:
  tls:
    - hosts:
        - hostname
  rules:
    - host: hostname
      http:
        paths:
          - path: /assets/static/
            pathType: ImplementationSpecific
            backend:
              service:
                name: servicename
                port:
                  number: 8080

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2025-01-17 17:32:52

所以事实证明应用程序有错误,它前面有另一个反向代理(它使用 Lua 和 Openresty 进行 oauth 注册)。
需要在那里提升 Proxy-body-size 属性。之后文件上传工作

So it turns out the Application wich had the error, had another reverse Proxy infront of it (wich uses Lua and Openresty for oauth registration).
The Proxy-body-size attribute needed to be raised there to. After that the File upload worked

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文