Nginx Google云TCP负载均衡器转发ip
我使用谷歌云TCP负载均衡器将请求转发到Kubernetes NGINX服务。正如所料,NGINX上的日志显示了负载平衡器IP。如何检索实际IP使用$http\u x\u forwarded\u for variable来记录用户的原始IP。来自 因此,在nginx上应使用$http_x_forwarded_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; ... } 如
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