【问题标题】:Google Cloud Kubernetes Laravel Get Visitor IPGoogle Cloud Kubernetes Laravel 获取访问者 IP
【发布时间】: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


【解决方案1】:

你必须在你的 nginx 服务中设置流量策略

externalTrafficPolicy: "Local"

还有

healthCheckNodePort: "numeric port number for the service"

Preserving the client source IPdoc 中的更多详细信息

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 2015-02-09
    • 2019-12-22
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多