---
title: "Configure TCP → Proxy Rule"
sidebar_label: "Configure TCP → Proxy Rule"
sidebar_position: 3
description: "How to see real client IP addresses"
---

import Formbricks from '@theme/MDXComponents/Formbricks'

import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from '@selectel/docux/components'

# 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](https://docs.nginx.com/nginx/admin-guide/load-balancer/using-proxy-protocol/#changing-the-load-balancers-ip-address-to-the-client-ip-address) instruction in the nginx documentation.

<Tabs queryString="tcp-proxy">
  <TabItem value="http" default>
    <TabItemLabel>
      For HTTP
    </TabItemLabel>

    1. Ensure you have [created a load balancer](/cloud-servers/load-balancers/create-load-balancer.mdx) with the following parameters:

       * for the [target group](/cloud-servers/load-balancers/about-load-balancers.mdx#target-groups) — PROXY protocol and port 80;
       * for the [rule](/cloud-servers/load-balancers/about-load-balancers.mdx#rules) — TCP protocol and port 80.

       Available load balancers can be viewed in the [Control Panel](https://my.selectel.ru/vpc/default/lbaas/load-balancers/): in the top menu, click **Products** → **Cloud Servers** → **Load Balancers** → **Load Balancers \*\*\*\* tab**.

    2. [Connect to the cloud server](/cloud-servers/manage/connect-to-server.mdx) from the target group.

    3. Install and configure nginx:

       ```bash
       apt update
       apt install nginx
       systemctl start nginx
       ```

    4. Open the configuration file on the cloud server:

       ```bash
       nano /etc/nginx/sites-enabled/default
       ```

    5. Change the lines in the `server:` block:

       ```bash
       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](https://my.selectel.ru/vpc/default/lbaas/load-balancers/): 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](https://nginx.org/ru/docs/http/ngx_http_realip_module.html) in the nginx documentation.
  </TabItem>

  <TabItem value="https">
    <TabItemLabel>
      For HTTPS
    </TabItemLabel>

    1. Ensure you have [created a load balancer](/cloud-servers/load-balancers/create-load-balancer.mdx) with the following parameters:

       * for the [target group](/cloud-servers/load-balancers/about-load-balancers.mdx#target-groups) — PROXY protocol and port 80;
       * for the [rule](/cloud-servers/load-balancers/about-load-balancers.mdx#rules) — TCP protocol and port 80.

       Available load balancers can be viewed in the [Control Panel](https://my.selectel.ru/vpc/default/lbaas/load-balancers/): in the top menu, click **Products** → **Cloud Servers** → **Load Balancers** → **Load Balancers \*\*\*\* tab**.

    2. [Connect to the cloud server](/cloud-servers/manage/connect-to-server.mdx) from the target group.

    3. Install and configure nginx:

       ```bash
       apt update
       apt install nginx
       systemctl start nginx
       ```

    4. Open the configuration file on the cloud server:

       ```bash
       nano /etc/nginx/sites-enabled/default
       ```

    5. Change the lines in the `server:` block:

       ```bash
       server {
           listen 443 ssl proxy_protocol;

           ssl_certificate /etc/nginx/ssl/public.example.com.pem;
           ssl_certificate_key /etc/nginx/ssl/public.example.com.key;

           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](https://my.selectel.ru/vpc/default/lbaas/load-balancers/): 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](https://nginx.org/ru/docs/http/ngx_http_realip_module.html) in the nginx documentation.
  </TabItem>
</Tabs>

<Formbricks />
