Skip to main content

Configure TCP → Proxy Rule

Last update:

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.

  1. 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 ProductsCloud ServersLoad BalancersLoad Balancers **** tab.

  2. Connect to the cloud server from the target group.

  3. Install and configure nginx:

    apt update
    apt install nginx
    systemctl start nginx
  4. Open the configuration file on the cloud server:

    nano /etc/nginx/sites-enabled/default
  5. 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 example 192.168.0.3. You can view it in the Control Panel: in the top menu, click ProductsCloud ServersLoad BalancersLoad 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.