# ngx\_stream\_realip\_module

* [示例配置](/nginx-docs/he-xin-gong-neng/stream/ngx_stream_realip_module.md#example_configuration)
* [指令](/nginx-docs/he-xin-gong-neng/stream/ngx_stream_realip_module.md#directives)
  * [set\_real\_ip\_from](/nginx-docs/he-xin-gong-neng/stream/ngx_stream_realip_module.md#set_real_ip_from)
* [内嵌变量](/nginx-docs/he-xin-gong-neng/stream/ngx_stream_realip_module.md#embedded_variables)

`ngx_stream_realip_module` 模块用于将客户端地址和端口更改为 PROXY 协议头（1.11.4）中发送。必须先在 `listen` 指令中设置 [proxy\_protocol](/nginx-docs/he-xin-gong-neng/stream/ngx_stream_core_module.md#proxy_protocol) 参数才能启用 PROXY 协议。

该模块不是默认构建的，您可以在构建时使用 `--with-stream_realip_module` 配置参数启用。

## 示例配置 <a href="#example_configuration" id="example_configuration"></a>

```
listen 12345 proxy_protocol;

set_real_ip_from  192.168.1.0/24;
set_real_ip_from  192.168.2.1;
set_real_ip_from  2001:0db8::/32;
```

## 指令 <a href="#directives" id="directives"></a>

### set\_real\_ip\_from

|       - | 说明                                                      |
| ------: | ------------------------------------------------------- |
|  **语法** | **set\_real\_ip\_from** `address` \| `CIDR` \| `unix:`; |
|  **默认** | ——                                                      |
| **上下文** | stream、server                                           |

定义已知可发送正确替换地址的受信任地址。如果指定了特殊值 `unix:`，则所有 UNIX 域套接字将被信任。

## 内嵌变量 <a href="#embedded_variables" id="embedded_variables"></a>

* `$realip_remote_addr`

  保留原始客户端地址
* `$realip_remote_port`

  保留原始的客户端端口

## 原文档

<http://nginx.org/en/docs/stream/ngx_stream_realip_module.html>


---

# Agent Instructions: 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:

```
GET https://docshome.gitbook.io/nginx-docs/he-xin-gong-neng/stream/ngx_stream_realip_module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
