TrustedProxy无法检测到用户IP [英] TrustedProxy does not detect User IP
问题描述
我正在ELB和Cloudflare后面的EC2上使用Laravel 5.3和PHP7,并且TrustedProxy软件包有一个小问题(
I'm using Laravel 5.3 with PHP7 on an EC2 behind an ELB and Cloudflare and I have a little problem with TrustedProxy package(https://github.com/fideloper/TrustedProxy).
该软件包没有给我用户Ip.
The package doesn't give me the user Ip.
在受信任的配置文件中,我有类似的内容
In the trusted config file I have something like this
return [
'proxies' => '*',
'headers' => [
\Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR',
\Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST',
\Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO',
\Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT',
],
];
(我也尝试过使用**)
(I tried with ** too)
但是当我执行$ request-> ip(),$ request-> getClientIp或getClientIps之类的操作时(最后所有这些方法都使用getClientIps()),出现的IP是代理IP.
But when I do something like $request->ip(), $request->getClientIp o getClientIps (at the end all this method are using getClientIps()) the IP that appear is the proxy IP.
如果我打印$ request,我可以看到:
If I print the $request I can see:
服务器包:
...
"HTTP_X_FORWARDED_PROTO" => "https"
"HTTP_X_FORWARDED_PORT" => "443"
"HTTP_X_FORWARDED_FOR" => "XX.XX.XX.XX" (I removed the real IP)
...
"REMOTE_ADDR" => "10.0.0.53"
头包:
"x-forwarded-proto" => array:1 [
0 => "https"
]
"x-forwarded-port" => array:1 [
0 => "443"
]
"x-forwarded-for" => array:1 [
0 => "XX.XX.XX.XX" (I removed the real IP)
]
但是$ request-> ip(),$ request-> getClientIp和getClientIps返回错误的IP(10.0.0.53).
But the $request->ip(), $request->getClientIp and getClientIps return the wrong IP (10.0.0.53).
有人有想法或线索吗?
谢谢!
推荐答案
已解决. 主要问题(有点愚蠢)是中间件的顺序.我正在使用在trustproxy之前执行的中间件中的信息.
Solved. The main problem (and a bit stupid) is the order in the middelwares. I were using the information in a middleware executed before trustproxy.
这篇关于TrustedProxy无法检测到用户IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!