我正在尝试在负载均衡器下的Google Cloud Kubernetes Engine上使用Nginx的Laravel应用程序上获得访问者IP。
我已经这样设置TrustProxies.php:
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies = '*';
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
我也尝试过
protected $proxies = '**';
和
protected $proxies = ['loadbalancer_ip_here'];
无论我尝试了什么,它总是会返回负载均衡器ip。
这可能是由Nginx配置引起的吗?帮助表示赞赏。
答案 0 :(得分:1)
您必须在nginx服务中设置流量策略
externalTrafficPolicy: "Local"
还有
healthCheckNodePort: "numeric port number for the service"
Preserving the client source IP文档中的更多详细信息