【发布时间】:2019-10-14 23:48:04
【问题描述】:
我正在尝试在负载均衡器下使用 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 配置引起的吗?帮助表示赞赏。
【问题讨论】:
-
你是什么 Ingress 类?是你说的 nginx 还是你的容器中捆绑的 web 服务器的 nginx?
-
@MathieuBour Nginx 捆绑在容器中,只有 1 个应用程序在运行,因此没有使用 Ingress 类。
-
好吧,我建议你在问题中添加你的vhost,以便大家查看。
标签: laravel nginx kubernetes google-cloud-platform ip