我在获取正确的IP报头时遇到了一些问题。我正在使用以下代理设置:
Cloudflare ->亚马逊NLB ->入口-nginx (k8s)
我的ingress nginx有以下配置:
config:
use-forwarded-headers: "true"
real-ip-header: "CF-Connecting-IP"
forwarded-for-header: "CF-Connecting-IP"
set-real-ip-from: "0.0.0.0/0"
proxy-buffer-size: "16k"
proxy-buffers-number: "8"由于某些原因,x-real-ip报头是正确的,但x-forwarded-for报头不正确:
REMOTE ADDR: 127.0.0.1
X FORWARDED FOR: 10.0.102.38 <- Wrong
X-REAL-IP: xx.xxx.xxx.xxx <- Correctingress nginx负载均衡器(NLB)具有:
External Traffic Policy: Local如文件所示。和以下注释:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: 3600
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: *
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: xxxx
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: https
service.beta.kubernetes.io/aws-load-balancer-type: nlb为了安全起见,我还在应用程序的服务上启用了ExternalTrafficPolicy: Local,但无济于事。
在配置中启用use-proxy-protocol:"true“会破坏应用程序(可能是因为CloudFlare)。
2021-09-19 12:42:17
" while reading PROXY protocol, client: x.x.x.x, server: 0.0.0.0:80任何帮助都将不胜感激。
发布于 2021-09-19 20:26:40
Cloudflare支持X-Forwarded-For头,因此您可以尝试配置:
config:
[...]
forwarded-for-header: "X-Forwarded-For"您似乎能够在您的设置中正确读取CF-Connecting-IP,因此来自Cloudflare的请求中也应该可以使用X-Forwarded-For。
有关更多信息,请访问refer to the support article。
https://stackoverflow.com/questions/69243271
复制相似问题