[英]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.