【问题标题】:Using Xdebug when the php application sits behind Varnish当 php 应用程序位于 Varnish 后面时使用 Xdebug
【发布时间】:2015-02-20 02:10:35
【问题描述】:

我正在尝试使用 PHPStorm 将 Xdebug 远程调试设置为位于 Varnish 后面的站点作为缓存层。

Varnish 作为 80 端口上的前端,Apache 作为 8080 端口上的后端与之通信。

如果我绕过 Varnish 并直接与端口 8080 上的站点对话 Xdebug 和 Phpstorm 按预期工作,但是我并没有真正正确地测试系统 - 我真正需要做的是触发调试会话,即使请求通过 Varnish 代理。

显然我不希望缓存的内容触发调试会话,但未缓存的内容仍然应该。

我的Xdebug设置如下:

; xdebug
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.scream=0
xdebug.cli_color=1
xdebug.show_local_vars=1

【问题讨论】:

    标签: php phpstorm xdebug varnish


    【解决方案1】:

    Xdebug 从 2.2.0 开始支持尝试连接回 X_HTTP_FORWARDED_FOR 中提供的 IP(修复了 2.2.2 中的错误),请参阅错误 #598#660。根据您的 Varnish 版本,您可能需要添加标题,或者可能由 varnish 为您设置。

    如果您设置标题,您的原始配置应该可以工作。

    添加vcl_recv:

    if (req.http.x-forwarded-for) {
         set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
    } else {
         set req.http.X-Forwarded-For = client.ip;
    }
    

    【讨论】:

    • 啊哈-这可以解释为什么它不起作用,运行默认的 xdebug 2.1,因为这似乎是 Ubuntu 12.04LTS 存储库中的版本。谢谢!
    【解决方案2】:

    像往常一样问问题暴露了答案......

    似乎开箱即用的请求 IP 地址没有通过 varnish 映射到 php 为 $_SERVER[REMOTE_ADDR],因此启用 remote_connect_back 后,Xdebug 尝试连接回的不是 PHPStorm,而是连接到 Varnish 本身。

    更改 xdebug 设置以显式设置 remote_host 解决了如下问题:

    ; xdebug
    xdebug.remote_enable = 1
    xdebug.remote_connect_back = 0
    xdebug.remote_host = 192.168.150.1
    xdebug.remote_port = 9000
    xdebug.scream=0
    xdebug.cli_color=1
    xdebug.show_local_vars=1
    

    在这种情况下,它对我来说很好,因为我总是从 192.168.150.1 请求(这是我的开发虚拟机的主机)

    我猜想一个更通用的解决方案是将 REMOTE_ADDR 字段重新映射到原始 IP 而不是 Varnish 的 IP。

    【讨论】:

    • 经过验证的解决方案已经在我的 varnish vcl 中设置,我使用 xdebug 2.4.0 但是问题仍然存在。但是使用此解决方案对我有用
    猜你喜欢
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2019-12-20
    相关资源
    最近更新 更多