【问题标题】:X-Forwarded-For 127.0.0.6 when using IPv6X-Forwarded-For 127.0.0.6 使用 IPv6 时
【发布时间】:2017-01-07 08:27:12
【问题描述】:

我正在使用带有 Apache 2.4 的 mod_remoteip 将 X-Forwarded-For 标头分配给客户端 ip 字段,以便在我在负载均衡器后面时正确记录客户端 ip。负载均衡器为每个请求添加 X-Forwaded-For 标头,并始终通过 IPv6 访问网络服务器。

正如您在以下测试中看到的,当从外部通过 IPv6 时,IPv6 请求只是将 127.0.0.6 显示为客户端 IP,而不是真实的客户端 IP。使用 IPv4 就可以了。

负载平衡器 IP 是 2a02:2e0:40c:102::5

网络服务器IP是2a02:2e0:40c:102:1::10

我的客户地址是5.199.135.102 + 2001:4ba0:ffff:ea::5

IPv6 请求

curl -6 http://foo.bar/ -I

网络服务器上网络级别的请求/响应

####
T 2a02:2e0:40c:102::5:41974 -> 2a02:2e0:40c:102:1::10:80 [AP]
HEAD / HTTP/1.1.
User-Agent: curl/7.29.0.
Host: foo.bar.
Accept: */*.
X-Forwarded-For: 127.0.0.6.
Via: 1.1 [2a02:2e0:40c:ffff::3]:80.
X-Forwarded-For-Port: 57252.
.
##
T 2a02:2e0:40c:102:1::10:80 -> 2a02:2e0:40c:102::5:41974 [AP]
HTTP/1.1 302 Found.
Date: Tue, 30 Aug 2016 21:44:13 GMT.
Server: Apache.
Location: https://foo.bar/.
Content-Type: text/html; charset=iso-8859-1.
.

Apache 日志输出 IPv6

"127.0.0.6" 2a02:2e0:40c:102::5 - - [31/Aug/2016:00:07:15 +0200] "HEAD / HTTP/1.1" 302 - "-" "curl/7.29.0"

IPv4 请求

curl -4 http://foo.bar/ -I

网络服务器上网络级别的请求/响应

####
T 2a02:2e0:40c:102::5:21050 -> 2a02:2e0:40c:102:1::10:80 [AP]
HEAD / HTTP/1.1.
User-Agent: curl/7.29.0.
Host: foo.bar.
Accept: */*.
Via: 1.1 1.2.3.4:80.
X-Forwarded-For: 5.199.135.102.
X-Forwarded-For-Port: 56352.
.

##
T 2a02:2e0:40c:102:1::10:80 -> 2a02:2e0:40c:102::5:21050 [AP]
HTTP/1.1 302 Found.
Date: Tue, 30 Aug 2016 22:06:08 GMT.
Server: Apache.
Location: https://foo.bar/.
Content-Type: text/html; charset=iso-8859-1.
.
.

Apache 日志输出 IPv4

"5.199.135.102" 2a02:2e0:40c:102::5 - - [31/Aug/2016:00:06:08 +0200] "HEAD / HTTP/1.1" 302 - "-" "curl/7.29.0"

以前有人遇到过这个问题吗?如果您需要更多信息,请告诉我。

提前 THX - mat1010

【问题讨论】:

  • 这个问题在这里是题外话。在另一个网站上发布此内容时,请提供有关负载平衡器的信息。那是给你错误信息的设备,而你的问题没有提供任何关于它的信息

标签: curl http-headers ipv6 apache2.4


【解决方案1】:

就我而言,问题是mod_remoteip

负载均衡器在 via 标头中用括号伪装 IPv6 地址 Via: 1.1 [2a02:2e0:40c:ffff::3]:80

这是RFC7239 IPv6 地址符号的一部分,因为有时需要指定也用冒号分隔的端口。

mod_remoteip 无法解释此类地址。这在 Lee Maguire 的 apache 开发版本中的 mod_remoteip documentation 下方也有说明。

我假设 mod_remoteip 当前不支持 RFC 7239 语法 https://www.rfc-editor.org/rfc/rfc7239

X-Forwarded-For: 192.0.2.43, 2001:db8:cafe::17

变成:

转发:for=192.0.2.43, for="[2001:db8:cafe::17]"

【讨论】:

    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 2013-10-22
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多