简体   繁体   English

Google Cloud TCP负载均衡器转发IP

[英]Google Cloud TCP Load Balancer forward ip

I use Google Cloud TCP load balancer forwarding requests to a Kubernetes NGINX service. 我使用Google Cloud TCP负载平衡器将请求转发到Kubernetes NGINX服务。 As expected the logs on the NGINX show the Load Balancer IP. 如预期的那样,NGINX上的日志显示了负载均衡器IP。 How can I retrieve the actual IP 如何获取实际IP

使用$http_x_forwarded_for变量记录用户的原始IP。

The forwarded headers from the Load Balancer are 负载均衡器转发的标头是

X-Forwarded-For
X-Forwarded-Proto

Thus on nginx "$http_x_forwarded_for" shall be used 因此,在nginx上应使用“ $ http_x_forwarded_for”

location / {
  ...
  proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
  ...
}

If you are using Kubernetes and services you need to set the extrernal traffic policy to local 如果您正在使用Kubernetes和服务,则需要将外部流量策略设置为本地

kind: Service
apiVersion: v1
metadata:
  name: proxy-service
spec:
  selector:
    app: the-application
  type: LoadBalancer
  externalTrafficPolicy: Local
  ports:
  - protocol: TCP
    port: 443
    targetPort: 443
    name: https

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Google Cloud Load Balancer和cloudflare获取真正的IP - Getting real ip from Google Cloud Load Balancer and cloudflare 使用 Google Cloud Kubernetes TCP 负载均衡器的 Nginx 状态代码 499 - Nginx Status Code 499 using Google Cloud Kubernetes TCP Load Balancer 谷歌云计算负载均衡器504错误 - google cloud compute load balancer 504 error 将所有 TCP 和 UDP 端口从负载均衡器转发到 Azure Kubernetes 服务上的 nginx 入口 - Forward all TCP and UDP ports from load balancer to nginx ingress on Azure Kubernetes Service 如何使用Google Cloud Load Balancer和Nginx作为Web服务器强制使用SSL - How to force ssl with Google Cloud Load Balancer and nginx as a web server 将 Nginx 配置为 TCP 负载均衡器 - Configure Nginx to be a TCP load balancer Google云负载平衡器未返回Content-Encoding:gzip - Google cloud load balancer not returning Content-Encoding: gzip AKS 标准负载均衡器 TCP 重置注释 - AKS Standard Load Balancer TCP Reset Annotations 带有TCP TLS到Nginx的AWS Classic负载均衡器 - AWS Classic Load Balancer with TCP TLS to Nginx 使用$ http_x_forwarded_proto强制使用NGINX上的www和https重定向作为Google云负载均衡器的后端 - Forcing www and https redirect on NGINX as backend of Google cloud Load Balancer using $http_x_forwarded_proto
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM