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