nginx 上传 文件超时设置_Ingressnginx自定义配置文件
點擊上方藍色字體,關注我們
讀完需 8 分鐘
速讀需?4 分鐘
k8s集群默認安裝的ingress-nginx直接投入測試或生產使用,其不合適的配置參數可能會導致一些訪問報錯。
例如:
“413 Request Entity Too Large”
“503 Service Unavailable”
此時我們就需要調整ingress-nginx的配置參數來解決問題,有以下三種方式:
ConfigMap
使用ConfigMap設置Nginx的全局配置文件Annotations
使用Annotations設置特定的Server的配置文件,如:某個hello.test.cnCustom Template
使用模板設置更多的特定Server的配置文件
在此只介紹下比較常見的ConfigMap、Annotations兩種方式。
需求
在此主要以解決以下兩個問題為例:
“413 Request Entity Too Large”
此問題為上傳文件過大導致,nginx默認限制為1M,可以通過調整client_max_body_size參數解決。
upstream超時
upstream超市可能會導致502、503、504等問題,nginx默認超時時間為60s,可以通過設置proxy_read_timeout、proxy_connect_timeout、proxy_send_timeout參數解決。
ConfigMap
1.?默認配置
默認ingress-nginx的ConfigMap有以下三種并且數據都為空
# 默認的三種ConfigMap# kubectl get cm -n ingress-nginxNAME DATA AGEingress-controller-leader-nginx 0 10dnginx-configuration 0 10dtcp-services 0 10dudp-services 0 10d# ConfigMap定義# vim mandatory# 截取ConfigMap部分---kind: ConfigMapapiVersion: v1metadata: name: nginx-configuration namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx---kind: ConfigMapapiVersion: v1metadata: name: tcp-services namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx---kind: ConfigMapapiVersion: v1metadata: name: udp-services namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx????app.kubernetes.io/part-of:?ingress-nginx其中:
三種ConfigMap都沒有Data設置,因此數據定義都為空;
nginx-ingress-controller分別引用nginx-configuration、 tcp-services、 udp-services三個ConfigMap。
2.自定義設置
調整參數我們需要選擇對應的ConfigMap,經過測試需要選擇nginx-configuration。
注意:
使用nginx-configuration,而不是tcp-services和udp-services。
經測試,按照官網"https://kubernetes.github.io/ingress-nginx/examples/customization/custom-configuration/"設置,ConfigMap使用ingress-nginx-controller是不生效的,因為沒有ingress-nginx-controller這個ConfigMap,需要使用nginx-configuration。
在此我將全局配置文件單獨列出,也可以將其合并到mandatory.yaml中。
Annotations
ConfigMap適用于全局配置,但是有時我們只需要針對某個特定的站點設置,此時就需要用到Annotations。
例如:要對hello.test.cn 這個站設置client_max_body_size解決上傳文件太大問題。
# vim hellworld.yaml# 單獨設置IngressapiVersion: extensions/v1beta1kind: Ingressmetadata: name: helloworld namespace: test annotations: nginx.ingress.kubernetes.io/proxy-body-size: 300mspec: rules: - host: hello.test.cn http: paths: - path: / backend: serviceName: helloworld servicePort: 8080# 應用# kubectl apply -f helloworld.yaml# 驗證# kubectl exec -it nginx-ingress-controller-gmzq6 -n ingress-nginx -- cat /etc/ngclient_max_body_size????????????????????300m;此時client_max_body_size只針對hello.test.cn 這個server生效,其他server仍然使用的是全局配置文件。
總結
在ingress-nginx的配置文件/etc/nginx/nginx.conf中指定了Global filters、TCP services、UDP services區域,應該分別對應三個ConfigMap。
熟悉了ingress-nginx的自定義配置后,我們就可以靈活修改配置參數了。
k8s node節點停機維護,pod如何遷移?
K8S+Jenkins實現SpringBoot項目的CI/CD
Jenkins擴展共享庫進階
Ventoy:新一代多系統啟動U盤解決方案
面對中小企業的開源運維平臺spug
Docker動態構建Jenkins Slave
關注我們總結
以上是生活随笔為你收集整理的nginx 上传 文件超时设置_Ingressnginx自定义配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 武大计算机几天出录取结果,录取大概要几天
- 下一篇: 调用kmeans_聚类分析—KMeans