Apache HTTP 服务器版本 2.4

| 描述 | 使用代理或负载均衡器通过请求头提供的用户代理 IP 地址列表替换连接的原始客户端 IP 地址。 |
|---|---|
| 状态 | 基础 |
| 模块标识符 | remoteip_module |
| 源文件 | mod_remoteip.c |
此模块用于将发起请求的用户代理视为 httpd 识别为源用户代理,用于授权和日志记录,即使该用户代理位于负载均衡器、前端服务器或代理服务器之后。
该模块使用 RemoteIPHeader 指令配置的请求头中报告的用户代理 IP 地址覆盖连接的客户端 IP 地址。
此外,此模块在使用 RemoteIPProxyProtocol 指令时实现了 HAProxy 的 PROXY 协议 的服务器端。
一旦按照指示替换,此覆盖的用户代理 IP 地址将用于 mod_authz_host Require ip 功能,由 mod_status 报告,并由 mod_log_config %a 和 core %a 格式字符串记录。连接的底层客户端 IP 可在 %{c}a 格式字符串中获得。

RemoteIPHeader
RemoteIPInternalProxy
RemoteIPInternalProxyList
RemoteIPProxiesHeader
RemoteIPProxyProtocol
RemoteIPProxyProtocolExceptions
RemoteIPTrustedProxy
RemoteIPTrustedProxyListApache 默认情况下使用连接的 client_ip 值识别用户代理,连接的 remote_host 和 remote_logname 由此值派生。这些字段在其他可加载模块的认证、授权、日志记录和其他目的中发挥作用。
mod_remoteip 在请求期间使用代理或负载均衡器提供的广告用户代理 IP 覆盖连接的客户端 IP。负载均衡器可能会与服务器建立一个长期存在的保持活动连接,并且每个请求都将具有正确用户代理 IP,即使负载均衡器的底层客户端 IP 地址保持不变。
当头值中列出多个以逗号分隔的用户代理 IP 地址时,它们将以从右到左的顺序进行处理。当给定用户代理 IP 地址不被信任以呈现前面的 IP 地址时,处理将停止。头字段将更新为此剩余的未确认 IP 地址列表,或者如果所有 IP 地址都被信任,则此头将从请求中完全删除。
在覆盖客户端 IP 时,该模块将中间主机列表存储在 remoteip-proxy-ip-list 注释中,mod_log_config 可以使用 %{remoteip-proxy-ip-list}n 格式标记记录该注释。如果管理员需要将其存储为附加头,则可以使用 RemoteIPProxiesHeader 指令将相同的值记录为头。
RemoteIPInternalProxy 内部(内联网)代理时由 mod_remoteip 评估。| 描述 | 声明应解析以获取用户代理 IP 地址的头字段 |
|---|---|
| 语法 | RemoteIPHeader header-field |
| 默认值 | 无 |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPHeader 指令触发 mod_remoteip 将指定 header-field 头的值视为用户代理 IP 地址或中间用户代理 IP 地址列表,这取决于 RemoteIPInternalProxy 和 RemoteIPTrustedProxy 指令的进一步配置。除非使用这些其他指令,否则 mod_remoteip 将信任所有呈现 RemoteIPHeader IP 值的主机。
RemoteIPHeader X-Client-IP
RemoteIPHeader X-Forwarded-For
| 描述 | 声明信任以呈现 RemoteIPHeader 值的客户端内联网 IP 地址 |
|---|---|
| 语法 | RemoteIPInternalProxy proxy-ip|proxy-ip/subnet|hostname ... |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPInternalProxy 指令添加一个或多个地址(或地址块)以信任为呈现用户代理 IP 的有效 RemoteIPHeader 值。与 RemoteIPTrustedProxy 指令不同,当从这些代理传递时,此头中呈现的任何 IP 地址(包括私有内联网地址)都将被信任。
RemoteIPHeader X-Client-IP RemoteIPInternalProxy 10.0.2.0/24 RemoteIPInternalProxy gateway.localdomain
| 描述 | 声明信任以呈现 RemoteIPHeader 值的客户端内联网 IP 地址 |
|---|---|
| 语法 | RemoteIPInternalProxyList filename |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPInternalProxyList 指令指定在启动时解析的文件,并构建一个地址(或地址块)列表以信任为呈现用户代理 IP 的有效 RemoteIPHeader 值。
'#' 井号字符指定注释行,否则每个空格或换行符分隔的条目都将与 RemoteIPInternalProxy 指令相同的方式进行处理。
RemoteIPHeader X-Client-IP RemoteIPInternalProxyList conf/trusted-proxies.lst
# Our internally trusted proxies; 10.0.2.0/24 #Everyone in the testing group gateway.localdomain #The front end balancer
| 描述 | 声明将记录所有中间 IP 地址的头字段 |
|---|---|
| 语法 | RemoteIPProxiesHeader HeaderFieldName |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPProxiesHeader 指令指定一个头,mod_remoteip 将在其中收集所有信任以解析请求的用户代理 IP 的中间客户端 IP 地址列表。请注意,中间 RemoteIPTrustedProxy 地址将记录在此头中,而任何中间 RemoteIPInternalProxy 地址将被丢弃。
RemoteIPHeader X-Forwarded-For RemoteIPProxiesHeader X-Forwarded-By
| 描述 | 启用或禁用 PROXY 协议处理 |
|---|---|
| 语法 | RemoteIPProxyProtocol On|Off |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
| 兼容性 | RemoteIPProxyProtocol 仅在 httpd 2.4.31 及更高版本中可用 |
RemoteIPProxyProtocol 指令启用或禁用 PROXY 协议连接头的读取和处理。如果使用 On 标志启用,则上游客户端必须在每次打开连接时发送头,否则连接将被中止,除非它在 RemoteIPProxyProtocolExceptions 指令提供的禁用主机列表中。
虽然此指令可以在任何虚拟主机中指定,但重要的是要理解,由于 PROXY 协议是基于连接的且与协议无关,因此启用和禁用实际上是基于 IP 地址和端口的。这意味着,如果您对同一主机和端口具有多个基于名称的虚拟主机,并且您为其中任何一个启用它,那么它将为所有虚拟主机启用(具有该主机和端口)。这也意味着,如果您尝试在一个虚拟主机中启用 PROXY 协议,而在另一个虚拟主机中禁用,则该操作将不起作用;在这种情况下,最后一个虚拟主机获胜,并且将记录一条通知,指示哪个设置被覆盖。
Listen 80
<VirtualHost *:80>
ServerName www.example.com
RemoteIPProxyProtocol On
#Requests to this virtual host must have a PROXY protocol
# header provided. If it is missing, the connection will
# be aborted
</VirtualHost>
Listen 8080
<VirtualHost *:8080>
ServerName www.example.com
RemoteIPProxyProtocol On
RemoteIPProxyProtocolExceptions 127.0.0.1 10.0.0.0/8
#Requests to this virtual host must have a PROXY protocol
# header provided. If it is missing, the connection will
# be aborted except when coming from localhost or the
# 10.x.x.x RFC1918 range
</VirtualHost>
| 描述 | 禁用对某些主机或网络的 PROXY 头的处理 |
|---|---|
| 语法 | RemoteIPProxyProtocolExceptions host|range [host|range] [host|range] |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
| 兼容性 | RemoteIPProxyProtocolExceptions 仅在 httpd 2.4.31 及更高版本中可用 |
RemoteIPProxyProtocol 指令启用或禁用 PROXY 协议连接头的读取和处理。有时,希望要求客户端提供 PROXY 头,但允许其他客户端在没有头的情况下连接。此指令允许服务器管理员配置单个主机或 CIDR 主机范围,这些主机或范围可以这样做。这通常对监控和管理流量到上游负载均衡器后面的虚拟主机服务器很有用。
| 描述 | 声明信任以呈现 RemoteIPHeader 值的客户端内联网 IP 地址 |
|---|---|
| 语法 | RemoteIPTrustedProxy proxy-ip|proxy-ip/subnet|hostname ... |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPTrustedProxy 指令添加一个或多个地址(或地址块)以信任为呈现用户代理 IP 的有效 RemoteIPHeader 值。与 RemoteIPInternalProxy 指令不同,这些代理报告的任何内联网或私有 IP 地址(包括 10/8、172.16/12、192.168/16、169.254/16 和 127/8 块(或在 IPv6 公共 2000::/3 块之外)都不会被信任为用户代理 IP,并且将保留在 RemoteIPHeader 头的值中。
RemoteIPHeader X-Forwarded-For RemoteIPTrustedProxy 10.0.2.16/28 RemoteIPTrustedProxy proxy.example.com
| 描述 | 声明信任以呈现 RemoteIPHeader 值的客户端内联网 IP 地址 |
|---|---|
| 语法 | RemoteIPTrustedProxyList filename |
| 上下文 | 服务器配置、虚拟主机 |
| 状态 | 基础 |
| 模块 | mod_remoteip |
RemoteIPTrustedProxyList 指令指定在启动时解析的文件,并构建一个地址(或地址块)列表以信任为呈现用户代理 IP 的有效 RemoteIPHeader 值。
'#' 井号字符指定注释行,否则每个空格或换行符分隔的条目都将与 RemoteIPTrustedProxy 指令相同的方式进行处理。
RemoteIPHeader X-Forwarded-For RemoteIPTrustedProxyList conf/trusted-proxies.lst
# 识别外部代理;
192.0.2.16/28 # wap 手机代理组
proxy.isp.example.com # 一些知名的 ISP