Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx Google云TCP负载均衡器转发ip_Nginx_Google Cloud Platform_Google Cloud Load Balancer - Fatal编程技术网

Nginx Google云TCP负载均衡器转发ip

Nginx Google云TCP负载均衡器转发ip,nginx,google-cloud-platform,google-cloud-load-balancer,Nginx,Google Cloud Platform,Google Cloud Load Balancer,我使用谷歌云TCP负载均衡器将请求转发到Kubernetes NGINX服务。正如所料,NGINX上的日志显示了负载平衡器IP。如何检索实际IP使用$http\u x\u forwarded\u for variable来记录用户的原始IP。来自 因此,在nginx上应使用$http_x_forwarded_ location / { ... proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ... } 如

我使用谷歌云TCP负载均衡器将请求转发到Kubernetes NGINX服务。正如所料,NGINX上的日志显示了负载平衡器IP。如何检索实际IP

使用$http\u x\u forwarded\u for variable来记录用户的原始IP。

来自

因此,在nginx上应使用$http_x_forwarded_

location / {
  ...
  proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
  ...
}
如果使用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
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