Configure TCP → Proxy Rule
To see the real IP addresses of clients accessing the load balancer, you can create a TCP → Proxy rule and use the Proxy Protocol. Client information will be added to the connection header.
For more information, see the Changing the Load Balancer's IP Address to the Client IP Address guide in the nginx documentation.
For HTTP
For HTTPS
-
Make sure that you created a load balancer with the following parameters:
- for the target group — PROXY protocol and port 80;
- for the rule — TCP protocol and port 80.
You can view available load balancers in the Control Panel: in the top menu, click Products → Cloud Servers → Load Balancers → Load Balancers tab.
-
Connect to the cloud server from the target group.
-
Install and configure nginx:
apt updateapt install nginxsystemctl start nginx -
Open the configuration file on the cloud server:
nano /etc/nginx/sites-enabled/default -
Change the lines in the
serverblock:server {listen 80 proxy_protocol;set_real_ip_from <loadbalancer_ip_address>;real_ip_header proxy_protocol;...}Specify
<loadbalancer_ip_address>— the private IP address of the load balancer, for example192.168.0.3. You can view it in the Control Panel: in the top menu, click Products → Cloud Servers → Load Balancers → Load Balancers tab → load balancer page → Settings section → Network field. It is used as a trusted address — for more information about the set_real_ip_from directive, see the nginx documentation.