> For the complete documentation index, see [llms.txt](https://docs.vngcloud.vn/vng-cloud-document/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vngcloud.vn/vng-cloud-document/load-balancer/network-load-balancer/common-use-cases/config-protocol-proxy-with-member-nginx.md).

# Config protocol Proxy with member Nginx

Protocol Proxy là một protocol đặc thù cho phép Load Balanacer chuyển tiếp thông tin kết nối của end-user (client connection information) đến các Member servers. Từ đó các Member Servers sẽ có thông tin để cấu hình các tính năng nâng cao như Rate-limit by IP, GeoIP, thống kê log access của client,.... Để sử dụng Protocol Proxy, bạn cần tạo vLB Layer 4 với Pool Settings là Proxy Protocol, đồng thời Member Server của bạn phải hỗ trợ Protocol Proxy này. Một số Web Server phổ biến đã hỗ trợ Proxy Protocol là Nginx, Apache,... Bài hướng dẫn này sẽ dùng Nginx.

* **Bước 1**: Bạn tạo Pool với Setting là Proxy Protocol:
* **Bước 2:** Trên Nginx server, kiểm tra module proxy protocol **http\_realip\_module** đã được cài đặt trước hay chưa bằng command. Nếu chưa, bạn cần install hoặc rebuild nginx từ source với module trên.

| `nginx -V 2>&1` `\| grep -- 'http_realip_module'` |
| ------------------------------------------------- |

<figure><img src="/files/j7YvYrSkanOhqsxuHCDQ" alt=""><figcaption></figcaption></figure>

**\* Chú ý**: Module này sẽ được install sẵn từ version **Ubuntu Bionic Beaver (18.04).**

* **Bước 3:** Cấu hình bật Proxy Protocol tại Virtual Host:

**+** Cấu hình thêm tham số **proxy\_protocol** tại **server {}** bloc&#x6B;**:**

<figure><img src="/files/szFpoCzh0TULyOqzeVGY" alt=""><figcaption></figcaption></figure>

\+ Xác định Load Balancer IP nơi mình nhận traffic Proxy Protocol tại **server {}** block với cấu hình **set\_real\_ip\_from**

| `set_real_ip_from <Load balancer IP>;` |
| -------------------------------------- |

VD: ở đây IP của vLB đang là 103.245.248.204.

<figure><img src="/files/qb8PRxZKHn8uzuLOgPxo" alt=""><figcaption></figcaption></figure>

\+ Cấu hình thay đổi IP của Load balancer với IP của client, được lấy từ Proxy Protocol Header tại **server {}** block với cấu hình **real\_ip\_header** và tham số **proxy\_protocol**

| `real_ip_header proxy_protocol;` |
| -------------------------------- |

<figure><img src="/files/co8sRbwuu5fxO9rJAu7O" alt=""><figcaption></figcaption></figure>

* **Bước 4:** Cấu hình Header để lấy giá trị xuất log tại **http {}** block với cấu hình **proxy\_set\_header**

| <p><code>proxy\_set\_header X-Real-IP $proxy\_protocol\_addr;</code><br><code>proxy\_set\_header X-Forwarded-For $proxy\_protocol\_addr;</code></p> |
| --------------------------------------------------------------------------------------------------------------------------------------------------- |

<figure><img src="/files/w2lkJn2JRBKBk8nIMRL6" alt=""><figcaption></figcaption></figure>

* **Bước 5:** Cấu hình Custom log với giá trị Client IP (Optional nếu bạn cần xuất log nginx kèm theo log client ip).

Định nghĩa log\_format custom có kèm theo Client IP

<figure><img src="/files/MMtNVsfoOnoYeJUx2jvl" alt=""><figcaption></figcaption></figure>

Thêm trong block **server{}** **access\_log** với log\_format là **custom** trên.

<figure><img src="/files/yvLO2qLuBONowHLfZRJO" alt=""><figcaption></figcaption></figure>

* **Bước 6:** Kiểm thử cấu hình và restart nginx để hoàn tất bằng command

| `nginx -t` |
| ---------- |

Nếu không có errror, bạn tiến hành restart nginx.

| `systemctl restart nginx` |
| ------------------------- |

* **Bước 7**: Thực hiện gửi request và kiểm tra log ra sẽ thấy IP Client xuất hiện trong log file:

<figure><img src="/files/tLmGejAOpIlUOlmPPRZ1" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.vngcloud.vn/vng-cloud-document/load-balancer/network-load-balancer/common-use-cases/config-protocol-proxy-with-member-nginx.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
