Technology Encyclopedia Home >Can the load balancer obtain the client IP directly?

Can the load balancer obtain the client IP directly?

Yes, a load balancer can obtain the client IP directly under certain configurations. This is often achieved through a feature known as "X-Forwarded-For" (XFF) or "proxy protocol".

In a typical setup, when a client sends a request to a server through a load balancer, the load balancer forwards the request to the appropriate backend server. By default, the backend server sees the IP address of the load balancer, not the client's IP. However, the load balancer can be configured to append the client's IP address to the HTTP headers, typically using the X-Forwarded-For header.

Example: A client with IP address 192.168.1.1 sends a request to a web application hosted on a server behind a load balancer with IP address 10.0.0.1. The load balancer forwards the request to the server and includes the client's IP in the X-Forwarded-For header, like so: X-Forwarded-For: 192.168.1.1. The server can then read this header to determine the original client's IP address.

In the context of cloud services, platforms like Tencent Cloud offer load balancing services that support obtaining the client IP. For instance, Tencent Cloud's CLB (Cloud Load Balancer) service can be configured to pass the client's IP address to the backend servers using the X-Forwarded-For header or the Proxy Protocol, ensuring that the backend servers can accurately identify and log the original client's IP.