# ngx\_stream\_realip\_module

* [示例配置](#example_configuration)
* [指令](#directives)
  * [set\_real\_ip\_from](#set_real_ip_from)
* [内嵌变量](#embedded_variables)

`ngx_stream_realip_module` 模块用于将客户端地址和端口更改为 PROXY 协议头（1.11.4）中发送。必须先在 `listen` 指令中设置 [proxy\_protocol](https://docshome.gitbook.io/nginx-docs/he-xin-gong-neng/ngx_stream_core_module#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>
