You need to enable JavaScript to run this app.
Load Balancer

Load Balancer

Copy page
Download PDF
Obtaining the client source IP address
Getting the client source IP for layer-7 listener
Copy page
Download PDF
Getting the client source IP for layer-7 listener
This topic introduces how the Layer 7 listener obtains the client source IP address accessing the Classic Load Balancer (CLB) service.​
Scenarios​
The Layer 7 listener of CLB (HTTP/HTTPS protocol) obtains the visitor's real IP address by configuring the backend server using the X-Forwarded-For method.​
The real IP address of the visitor will be placed by CLB in the X-Forwarded-For field of the HTTP header, and the first address in this field is the real IP address of the visitor.​
Configuration procedures​
​
Configure a Nginx server
Configure an Apache server
​
  1. Access the target backend server based on Logging on to a Linux instance.​
  1. Run the following command to install Nginx.​
  • ​
    yum install -y https://mirrors.ivolces.com/nginx_all/centos/7/x86_64/RPMS/nginx-1.22.0-1.el7.ngx.x86_64.rpm​
    ​
  1. Run the following command to check the Nginx version.​
  • ​
    nginx -v​
    ​
  • The output below indicates successful installation.​
  • ​
    nginx version: nginx/1.22.0​
    ​
  1. Run the following command to check the path of the Nginx configuration file, nginx.conf:​
  • ​
    find / -name nginx.conf​
    ​
  • The output is shown below, indicating that the path of the Nginx configuration file is /etc/nginx/nginx.conf.​
  • ​alt​​
  1. Run the following commands in sequence to back up the Nginx configuration file in its directory, then open the original Nginx configuration file.​
  • ​
    cd /etc/nginx​
    cp nginx.conf nginx.conf.bak​
    vi nginx.conf​
    ​
  1. Press it to enter edit mode, then add new configuration fields and details after the following server configuration information.​
  • ​
    server {​
    listen 80;​
    server_name localhost;​
    ​
  • Configuration fields and information to add:​
  • ​
    set_real_ip_from 100.64.0.0/10;​
    real_ip_header X-Forwarded-For;​
    ​
tip​
You can add the proxy server's network CIDR block into set_real_ip_from <IP_cidr> to obtain the IP address of the proxy server. For example, add the IP address range of the Cloud Load Balancer (100.64.0.0/10 is a reserved address range for the CLB, which cannot be allocated to other users, eliminating any security risks). Separate multiple IP address ranges with commas (,).​
  1. Press ESC to exit the editing mode, input :wq to save and exit the file.input​
  1. Run the following command to restart Nginx.​
  • ​
    systemctl restart nginx.service​
    ​
  1. Run the following command to check the path of the Nginx access log file, access.log:​
  • ​
    find / -name access.log​
    ​
  • The output is shown below, indicating that the path of the Nginx access log file is /var/log/nginx/access.log.​
  • ​alt​​
  1. Run the following command to view the Nginx access log and obtain the real visitor IP.​
tip​
cat /var/log/nginx/access.log​
​
Last updated: 2026.08.06 14:31:17