模块 ngx_http_realip_module
set_real_ip_from real_ip_header real_ip_recursive 嵌入变量的示例配置 Directives |
这ngx_http_realip_module
module 的
更改客户端地址和可选端口
发送到指定标头字段中发送的内容。
这个模块不是默认构建的,它应该使用--with-http_realip_module
configuration 参数。
示例配置
set_real_ip_from 192.168.1.0/24; set_real_ip_from 192.168.2.1; set_real_ip_from 2001:0db8::/32; real_ip_header X-Forwarded-For; real_ip_recursive on;
Directives
语法: |
set_real_ip_from
|
---|---|
默认值: | — |
上下文: |
http ,server ,location |
定义已知可正确发送的受信任地址
替换地址。
如果 special valueunix:
指定,
所有 UNIX 域套接字都将受信任。
也可以使用主机名 (1.13.1) 指定可信地址。
从版本 1.3.0 和 1.2.1 开始支持 IPv6 地址。
语法: |
real_ip_header
|
---|---|
默认值: |
real_ip_header X-Real-IP; |
上下文: |
http ,server ,location |
定义请求标头字段 其值将用于替换客户端地址。
包含可选端口的请求标头字段值 也用于替换客户端端口 (1.11.0)。 地址和端口应根据 RFC 3986 指定。
这proxy_protocol
参数 (1.5.12) 更改
客户端地址更改为 PROXY 协议标头中的客户端地址。
必须事先通过将proxy_protocol
参数
在 listen Directives中。
语法: |
real_ip_recursive |
---|---|
默认值: |
real_ip_recursive off; |
上下文: |
http ,server ,location |
此Directives出现在版本 1.3.0 和 1.2.1 中。
如果禁用递归搜索,则 匹配其中一个可信地址将替换为最后一个 address 在 real_ip_header Directives定义的请求标头字段中发送。 如果启用了递归搜索,则原始客户端地址 匹配其中一个可信地址将替换为最后一个 请求标头字段中发送的不受信任的地址。
嵌入变量
$realip_remote_addr
- 保留原始客户端地址 (1.9.7)
$realip_remote_port
- 保留原始客户端端口 (1.11.0)