问题描述
我正在尝试使用PHPStorm将Xdebug远程调试设置为位于Varnish后面作为缓存层的站点.
I'm trying to set up Xdebug remote debugging to a site sitting behind Varnish as a caching layer using PHPStorm.
Varnish作为80端口的前端,而Apache则将其作为8080端口的后端.
Varnish is sitting as a frontend on port 80 with Apache talking to it as a backend on port 8080.
如果我绕过Varnish并直接与端口8080上的站点进行对话,那么Xdebug和Phpstorm会按预期工作,但是我并没有真正正确地测试系统-我真正需要做的就是触发调试会话,即使在请求时通过Varnish代理.
If I bypass Varnish and talk directly to the site on port 8080 Xdebug and Phpstorm work as expected, however then I'm not really testing the system properly - what I really need to do is trigger a debug session even when the request is proxied through Varnish.
很明显,我不希望缓存的内容触发调试会话,但是未缓存的内容仍然应该触发.
Obviously I'm not expecting cached content to trigger a debug session, but uncached content still should.
我的Xdebug设置如下:
My Xdebug settings are as follows:
; 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
推荐答案
Xdebug自2.2.0开始支持尝试连接回X_HTTP_FORWARDED_FOR中提供的IP(已修复2.2.2中的错误),请参见错误#598 & #660 .根据您的Varnish版本,您可能必须添加标题,或者可能由清漆为您设置标题.
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.
添加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;
}
这篇关于当php应用程序位于Varnish后面时使用Xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!