K8S ingress 前端 header 傳遞參數后端獲取不到問題


原因∶
nginx 對 header name 的字符做了限制,默認underscores_in_headers 為off,表示如果 header name 中包含下划線,則忽略掉,部署后就獲取不到。
解決︰
1.在header里不要用“_"下划線,可以用駝峰命名或者其他的符號(如減號-)代替。nginx默認忽略掉下划線可能有些原因。
2.在nginx里的nginx.conf文件中配置 http 的部分添加: underscores_in_headers on;(默認值是off )

因為 K8S ingress 用了兩層 nignx,所以需要處理2個地方

  1. 物理機上的 nginx , http 下加入 underscores_in_headers on;

  2. 在 ingress-nginx 的 ConfiMap 添加 enable-underscores-in-headers: "true"

cd /data/yaml/ingress-nginx
cp deploy.yaml  deploy.yaml.20210617

vi deploy.yaml
# 找到下下面
# Source: ingress-nginx/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    helm.sh/chart: ingress-nginx-3.30.0
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/version: 0.46.0
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  # 添加下面這行
  enable-underscores-in-headers: "true"

# 重新加載
kubectl apply -f deploy.yaml


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM