Using Xdebug when the php application sits behind Varnish

房东的猫 提交于 2019-12-04 13:50:49

Xdebug has support to try to connect back to an IP provided in X_HTTP_FORWARDED_FOR since 2.2.0 (fixed a bug in 2.2.2), see bugs #598 & #660. Depending on your Varnish version you might have to add the header or it might be set for you by varnish.

If you set the header your original configuration should work.

Add in 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;
}

As usual asking the question exposed the answer...

It seems that out of the box the request IP address doesn't get mapped through varnish to php as $_SERVER[REMOTE_ADDR], so with remote_connect_back enabled Xdebug is attempting to connect back not to PHPStorm but instead to Varnish itself.

Changing the xdebug settings to explicitly set the remote_host solved the problem as follows:

; 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

In this case it works fine for me as I'm always requesting from 192.168.150.1 (this is the host machine for my dev VMs)

A more generic solution would I guess remap the REMOTE_ADDR field to the originating IP rather than Varnish's IP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!