Curl 使用IPv6时,X-Forwarded-For 127.0.0.6

Curl 使用IPv6时,X-Forwarded-For 127.0.0.6,curl,http-headers,ipv6,apache2.4,Curl,Http Headers,Ipv6,Apache2.4,我使用mod_remoteip和apache2.4将X-Forwarded-For头分配给client-ip字段,以便在我在loadbalancer后面时正确记录客户端ip。loadbalancer向每个请求添加X-Forwaded-For头,并始终通过IPv6访问Web服务器 正如您在以下测试中所看到的,当从外部通过IPv6时,IPv6请求只是将127.0.0.6显示为客户端IP,而不是真正的客户端IP。对于IPv4,这一切都很好 loadbancers IP为2a02:2e0:40c:102

我使用mod_remoteip和apache2.4将X-Forwarded-For头分配给client-ip字段,以便在我在loadbalancer后面时正确记录客户端ip。loadbalancer向每个请求添加X-Forwaded-For头,并始终通过IPv6访问Web服务器

正如您在以下测试中所看到的,当从外部通过IPv6时,IPv6请求只是将127.0.0.6显示为客户端IP,而不是真正的客户端IP。对于IPv4,这一切都很好

loadbancers IP为
2a02:2e0:40c:102::5

Web服务器的IP是
2a02:2e0:40c:102:1::10

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

IPv6请求

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

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

####
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.
.
####
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日志输出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-4http://foo.bar/ -我

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

####
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.
.
####
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在我的案例中,问题是mod_remoteip

loadbalancer在via标头中用类似的括号伪装IPv6地址
Via:1.1[2a02:2e0:40c:ffff::3]:80

这是IPv6地址表示法的一部分,因为有时需要指定也由冒号分隔的端口

mod_remoteip
无法解释此类地址。下面Lee Maguire在apache devel版本中也提到了这一点

我假设mod_remoteip当前不支持RFC 7239语法

X-For:192.0.2.432001:db8:cafe::17

变成:

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


这个问题在这里是离题的。在其他网站上发布此信息时,请提供有关负载平衡器的信息。这是一个给你错误信息的设备,而你的问题却没有给出任何信息