mod_remoteip
描述: | 用与代理或负载均衡器通过请求 headers 呈现的用户 IP 地址列表替换原始 client IP 地址。 |
状态: | Base |
模块标识符: | remoteip_module |
源文件: | mod_remoteip.c |
摘要
此模块用于将发起请求的用户视为 httpd 为了授权和 logging 而识别的原始用户,即使该用户在负载均衡器,前端服务器或代理服务器后面也是如此。
该模块使用RemoteIPHeader指令配置的请求标头中报告的 overragent IP 地址覆盖连接的 client IP 地址。
此外,当使用RemoteIPProxyProtocol指令时,此模块实现 HAProxy 的PROXY 协议的服务器端。
按照指示更换后,此覆盖的 useragent IP 地址将用于mod_authz_host要求 IP feature,由mod_status报告,并由mod_log_config%a
和核心%a
格式 strings 记录。连接的基础 client IP 以%{c}a
格式 string 提供。
至关重要的是仅从此服务器信任的中间主机(代理等)启用此行为,因为 remote useragent 模拟另一个 useragent 是微不足道的。
Remote IP 处理
Apache 默认使用连接的 client_ip value 标识 useragent,连接 remotehost 和 remotelogname 从此 value 派生。这些字段在其他可加载模块的身份验证,授权和 logging 以及其他目的中起作用。
在请求期间,mod_remoteip 将覆盖与代理或负载均衡器提供的通告的用户 IP 的连接的 client IP。负载均衡器可能与服务器建立 long live keepalive 连接,并且每个请求都将具有正确的 useragent IP,即使负载均衡器的基础客户端 IP 地址保持不变。
当标题 value 中列出多个以逗号分隔的 useragent IP 地址时,它们将在 Right-to-Left order 中处理。当不信任给定的 useragent IP 地址以呈现前面的 IP 地址时,处理停止。标头字段更新为此未确认 IP 地址的剩余列表,或者如果所有 IP 地址都受信任,则此标头将从请求中完全删除。
在覆盖 client IP 时,模块 store 存储 remoteip-proxy-ip-list 注释中的中间主机列表,mod_log_config可以使用%{remoteip-proxy-ip-list}n
格式令牌 record。如果管理员需要将此存储为附加标头,则同样的 value 也可以使用指令RemoteIPProxiesHeader作为标头 recording。
IPv4-over-IPv6 映射地址
与 httpd 一样,任何 IPv4-over-IPv6 映射地址都以 IPv4 表示形式记录。
内部(私人)地址
所有内部地址 10/8,172.16/12,192.168/16,169.254/16 和 127/8 块(以及公共 2000::/3 块之外的 IPv6 地址)仅在注册RemoteIPInternalProxy内部(内部网)代理时由 mod_remoteip 评估。
RemoteIPHeader 指令
描述: | 声明应该为使用者 IP 地址解析的头字段 |
句法: | RemoteIPHeader header-field |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPHeader指令触发mod_remoteip将指定 header-field 标头的 value 视为 useragent IP 地址或中间使用者 IP 地址列表,但需要进一步配置RemoteIPInternalProxy和RemoteIPTrustedProxy指令。除非使用这些其他指令,mod_remoteip将信任所有呈现RemoteIPHeader IP value 的主机。
内部(负载均衡器)Example
RemoteIPHeader X-Client-IP
代理 Example
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 指令
描述: | 声明受信任的 client Intranet IP 地址以显示 RemoteIPHeader value |
句法: | RemoteIPInternalProxy proxy-ip\|proxy-ip/subnet\|hostname ... |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPInternalProxy指令将一个或多个地址(或地址块)添加为信任,以表示使用者 IP 的有效 RemoteIPHeader value。与RemoteIPTrustedProxy指令不同,此标头中显示的任何 IP 地址(包括专用 Intranet 地址)在从这些代理传递时都是受信任的。
内部(负载均衡器)Example
RemoteIPHeader X-Client-IP RemoteIPInternalProxy 10.0.2.0/24 RemoteIPInternalProxy gateway.localdomain
RemoteIPInternalProxyList 指令
描述: | 声明受信任的 client Intranet IP 地址以显示 RemoteIPHeader value |
句法: | RemoteIPInternalProxyList filename |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPInternalProxyList指令指定在启动时解析的文件,并构建要信任的地址(或地址块)列表,以表示使用者 IP 的有效 RemoteIPHeader value。
'#
'哈希字符指定 comment line,否则每个空格或换行符分隔条目的处理方式与RemoteIPInternalProxy指令相同。
内部(负载均衡器)Example
RemoteIPHeader X-Client-IP RemoteIPInternalProxyList conf/trusted-proxies.lst
conf/trusted-proxies.lst 内容
# Our internally trusted proxies; 10.0.2.0/24 #Everyone in the testing group gateway.localdomain #The front end balancer
RemoteIPProxiesHeader 指令
描述: | 声明将记录所有中间 IP 地址的头字段 |
句法: | RemoteIPProxiesHeader HeaderFieldName |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPProxiesHeader指令指定一个标头,mod_remoteip将收集一个标题,列出所有可信赖的中间客户端 IP 地址,以解析请求的使用者 IP。请注意,中间RemoteIPTrustedProxy地址记录在此标头中,而任何中间RemoteIPInternalProxy地址都将被丢弃。
例
RemoteIPHeader X-Forwarded-For RemoteIPProxiesHeader X-Forwarded-By
RemoteIPProxyProtocol 指令
描述: | 启用或禁用 PROXY 协议处理 |
句法: | RemoteIPProxyProtocol On\|Off |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
兼容性: | RemoteIPProxyProtocol 仅在 httpd 2.4.31 和更新版本中可用 |
RemoteIPProxyProtocol
指令启用或禁用 PROXY 协议连接头的读取和处理。如果使用On
flag 启用,则上游 client 必须每隔 time 发送一次连接,否则连接将被中止,除非它位于RemoteIPProxyProtocolExceptions指令提供的禁用主机列表中。
虽然可以在任何虚拟 host 中指定此指令,但重要的是要理解,因为 PROXY 协议是基于连接和协议不可知的,所以启用和禁用实际上基于 IP 地址和 port。这意味着如果您有相同的 host 和 port 的多个 name-based 虚拟主机,并且为其中任何一个启用了它,则会为所有这些主机启用它(使用该 host 和 port)。这也意味着如果您尝试在一个中启用 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>
RemoteIPProxyProtocolExceptions 指令
描述: | 禁用某些主机或网络的 PROXY 标头处理 |
句法: | RemoteIPProxyProtocolExceptions host\|range[host\|range][host\|range] |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
兼容性: | RemoteIPProxyProtocolExceptions 仅在 httpd 2.4.31 和更新版本中可用 |
RemoteIPProxyProtocol
指令启用或禁用 PROXY 协议连接头的读取和处理。有时需要 clients 提供 PROXY 标头,但允许其他客户端在没有它的情况下连接。此指令允许服务器管理员配置可能执行此操作的单个主机或 CIDR 主机。这对于直接到上游负载均衡器后面的服务器的虚拟 host 的监视和管理流量通常很有用。
RemoteIPTrustedProxy 指令
描述: | 声明受信任的 client Intranet IP 地址以显示 RemoteIPHeader value |
句法: | RemoteIPTrustedProxy proxy-ip\|proxy-ip/subnet\|hostname ... |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPTrustedProxy指令将一个或多个地址(或地址块)添加为信任,以表示使用者 IP 的有效 RemoteIPHeader value。与RemoteIPInternalProxy指令不同,此类代理报告的任何 Intranet 或私有 IP 地址(包括 10/8,172.16/12,192.168/16,169.254/16 和 127/8 块(或 IPv6 公共 2000::/3 块之外)都不被信任为 useragent IP,并且保留在RemoteIPHeader标题的 value。
可信(负载均衡器)Example
RemoteIPHeader X-Forwarded-For RemoteIPTrustedProxy 10.0.2.16/28 RemoteIPTrustedProxy proxy.example.com
RemoteIPTrustedProxyList 指令
描述: | 声明受信任的 client Intranet IP 地址以显示 RemoteIPHeader value |
句法: | RemoteIPTrustedProxyList filename |
Context: | server config,virtual host |
状态: | Base |
模块: | mod_remoteip |
RemoteIPTrustedProxyList指令指定在启动时解析的文件,并构建要信任的地址(或地址块)列表,以表示使用者 IP 的有效 RemoteIPHeader value。
'#
'哈希字符指定 comment line,否则每个空格或换行符分隔条目的处理方式与RemoteIPTrustedProxy指令相同。
可信(负载均衡器)Example
RemoteIPHeader X-Forwarded-For RemoteIPTrustedProxyList conf/trusted-proxies.lst
conf/trusted-proxies.lst 内容
# Identified external proxies; 192.0.2.16/28 #wap phone group of proxies proxy.isp.example.com #some well known ISP