约 1 分钟阅读
云计算

k8s ingress-nginx 配置 header 转发

k8s 配置 use-forwarded-headers 来配置转发 header

k8s ingress-nginx 配置 header 转发
SYSTEM
194 次阅读约 1 分钟阅读

在使用 k8s 时如果使用了 ingress-nginx 来作为网关,通常又需要转发 headers,这个时候需要在 configMap 中配置如下内容实现 header 的转发:

YML
apiVersion: v1
data:
  allow-snippet-annotations: "true"
  enable-real-ip: "true"
  compute-full-forwarded-for: "true"
  use-forwarded-headers: "true"
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.7.1
  name: ingress-nginx-controller
  namespace: ingress-nginx

就需要增加 use-forwarded-headers: "true" 就可以实现转发 header 了。

这里附上官方解释:

use-forwarded-headers

If true, NGINX passes the incoming X-Forwarded-* headers to upstreams. Use this option when NGINX is behind another L7 proxy / load balancer that is setting these headers.

If false, NGINX ignores incoming X-Forwarded-* headers, filling them with the request information it sees. Use this option if NGINX is exposed directly to the internet, or it's behind a L3/packet-based load balancer that doesn't alter the source IP in the packets.

评论交流

暂无评论,欢迎分享您的见解