Kubernetes 和 Nginx 入口控制器的 413 错误 [英] 413 error with Kubernetes and Nginx ingress controller
问题描述
我正在尝试更改 client_max_body_size
值,因此我的 nginx 入口不会返回 413 错误.
I'm trying to change the client_max_body_size
value, so my nginx ingress will not return 413 error.
我测试了几个解决方案.
这是我的测试配置图:
I've tested few solutions.
Here is my test config map:
kind: ConfigMap
apiVersion: v1
data:
proxy-connect-timeout: "15"
proxy-read-timeout: "600"
proxy-send-timeout: "600"
proxy-body-size: "8m"
hsts-include-subdomains: "false"
body-size: "64m"
server-name-hash-bucket-size: "256"
client-max-body-size: "50m"
metadata:
name: nginx-configuration
namespace: ingress-nginx
labels:
app: ingress-nginx
这些改动一点作用都没有,加载之后,在nginx控制器日志中可以看到重新加载config map的信息,但是nginx.conf中的值是一样的:
These changes has no effect at all, after loading it, in the nginx controller log I can see the information about reloading config map, but the values in nginx.conf are the same:
root@nginx-ingress-controller-95db685f5-b5s6s:/# cat /etc/nginx/nginx.conf | grep client_max
client_max_body_size "8m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
client_max_body_size "1m";
我的 nginx-controller 配置使用这个镜像:quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.13.0
My nginx-controller config uses this image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.13.0
如何强制 nginx 更改值?我需要对所有入口进行全局更改.
How can I force the nginx to change the value? I need to change it globally, for all my ingresses.
推荐答案
您可以使用 annotation nginx.ingress.kubernetes.io/proxy-body-size
设置max-body-size 选项就在您的 Ingress 对象中,而不是更改基础 ConfigMap.
You can use the annotation nginx.ingress.kubernetes.io/proxy-body-size
to set the max-body-size option right in your Ingress object instead of changing a base ConfigMap.
以下是使用示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
...
这篇关于Kubernetes 和 Nginx 入口控制器的 413 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!