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.
Find more details in the Changing the load balancer's IP address to the client IP address instruction in the nginx documentation.
For HTTP
For HTTPS
-
Ensure you have 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.
Available load balancers can be viewed 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
server:block: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 block → Network field. It is used as a trusted address — learn more about the set_real_ip_from directive in the nginx documentation.