模块 ngx_http_realip_module

set_real_ip_from
real_ip_header
real_ip_recursive
嵌入变量的示例配置
Directives

使用 更改客户端地址和可选端口 发送到指定标头字段中发送的内容。ngx_http_realip_module

默认情况下,此模块不是构建的,应使用 configuration 参数启用它。--with-http_realip_module

示例配置

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 address | CIDR | unix:;
默认值:
上下文: http, ,serverlocation

定义已知可正确发送的受信任地址 替换地址。 如果指定了 special 值,则 所有 UNIX 域套接字都将受信任。 也可以使用主机名 (1.13.1) 指定可信地址。unix:

从版本 1.3.0 和 1.2.1 开始支持 IPv6 地址。

语法: real_ip_header field | X-Real-IP | X-Forwarded-For | proxy_protocol;
默认值:
real_ip_header X-Real-IP;
上下文: http, ,serverlocation

定义请求标头字段 其值将用于替换客户端地址。

包含可选端口的请求标头字段值 也用于替换客户端端口 (1.11.0)。 地址和端口应根据 RFC 3986 指定。

参数 (1.5.12) 更改 客户端地址更改为 PROXY 协议标头中的客户端地址。 必须事先通过设置参数 在 listen Directives中。proxy_protocolproxy_protocol

语法: real_ip_recursive on | off;
默认值:
real_ip_recursive off;
上下文: http, ,serverlocation

此Directives出现在版本 1.3.0 和 1.2.1 中。

如果禁用递归搜索,则 匹配其中一个可信地址将替换为最后一个 address 在 real_ip_header Directives定义的请求标头字段中发送。 如果启用了递归搜索,则原始客户端地址 匹配其中一个可信地址将替换为最后一个 请求标头字段中发送的不受信任的地址。

嵌入变量

$realip_remote_addr
保留原始客户端地址 (1.9.7)
$realip_remote_port
保留原始客户端端口 (1.11.0)