Google Cloud Kubernetes Laravel 获取访问者 IP
Google Cloud Kubernetes Laravel Get Visitor IP
我正在尝试在我的 Laravel 应用程序上获取访问者 IP,该应用程序在 Google Cloud Kubernetes Engine 上使用 Nginx,在负载均衡器下。
我这样设置 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'];
不管我怎么试,它总是return负载均衡器ip。
这可能是 Nginx 配置引起的?帮助表示赞赏。
您必须在您的 nginx 服务中设置流量策略
externalTrafficPolicy: "Local"
还有
healthCheckNodePort: "numeric port number for the service"
Preserving the client source IP 文档中有更多详细信息
我正在尝试在我的 Laravel 应用程序上获取访问者 IP,该应用程序在 Google Cloud Kubernetes Engine 上使用 Nginx,在负载均衡器下。
我这样设置 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'];
不管我怎么试,它总是return负载均衡器ip。
这可能是 Nginx 配置引起的?帮助表示赞赏。
您必须在您的 nginx 服务中设置流量策略
externalTrafficPolicy: "Local"
还有
healthCheckNodePort: "numeric port number for the service"
Preserving the client source IP 文档中有更多详细信息