Nginx + php-fpm:仅在xdebug服务器运行时出现错误的网关 [英] Nginx + php-fpm: Bad gateway only when xdebug server is running

查看:657
本文介绍了Nginx + php-fpm:仅在xdebug服务器运行时出现错误的网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当xdebug服务器从IntelliJ IDEA运行时,我从nginx获得 502 Bad Gateway 尝试加载我的网站以触发断点。

When xdebug server is running from IntelliJ IDEA, I get 502 Bad Gateway from nginx when I try loading my site to trigger breakpoints.

如果我停止xdebug服务器,该网站将按预期工作。

If I stop the xdebug server, the site works as intended.

所以,我无法运行调试器,但之前确实有效(!)。无法确定它突然停止工作的原因。

So, I'm not able to run the debugger, but it did work previously (!). Not able to pinpoint why it suddenly stopped working.

设置的简短说明(让我知道我是否需要对此进行扩展。)

A short explanation of the setup (let me know if I need to expand on this).

我的php应用程序在docker容器中运行,它使用<$ c链接到运行在不同容器中的nginx来自docker compose config的$ c> volumes_from 。

My php app is running in a docker container, and it is linked to nginx running in a different container using volumes_fromin the docker compose config.

启动应用程序后,我可以使用 phpinfo()进行验证; 已加载xdebug模块。

After starting the app, I can verify using phpinfo(); the xdebug module is loaded.

我的xdebug.ini具有以下内容:

My xdebug.ini has the following content:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=10.0.2.2
xdebug.remote_connect_back=0
xdebug.remote_port=5555
xdebug.idekey=complex
xdebug.remote_handler=dbgp
xdebug.remote_log=/var/log/xdebug.log
xdebug.remote_autostart=1

我通过以下步骤获得了remote_host(运行xdebug服务器的地址)的IP地址:

I got the ip address for remote_host (where the xdebug server is running) by these steps:

docker-machine ssh default
route -n | awk '/UG[ \t]/{print $2}' <-- Returns 10.0.2.2

为了验证我可以从我的php容器中到达调试服务器,我执行了以下步骤

To verify I could reach the debugging server from within my php container, I did the following steps

docker exec -it randomhash bash
nc -z -v 10.0.2.2 5555

根据xdebug提供以下输出服务器是否运行:

Giving the following output depending on xdebug server running or not:


  • 运行:连接到10.0.2.2 5555端口[tcp / *]成功!

  • 未运行: nc:连接到10.0.2.2端口5555(tcp)失败:连接被拒绝

  • Running: Connection to 10.0.2.2 5555 port [tcp/*] succeeded!
  • Not running: nc: connect to 10.0.2.2 port 5555 (tcp) failed: Connection refused

因此,IntelliJ IDEA肯定会设置为在5555上接收连接。我还在源文件路径和远程路径之间进行了适当的路径映射路径(从IDEA中设置PHP远程调试服务器时)。

So IntelliJ IDEA is surely set up to receive connections on 5555. I also did the appropriate path mapping between my source file paths and the remote path (when setting up the PHP Remote Debugging server from within IDEA).

任何想法?由于我对这些技术没有多少经验,所以有点丢失:D

Any ideas? Kind of lost on this one as I don't have much experience with any of these technologies :D

推荐答案

这有时会发生,原因是php-fpm和xdebug中的错误(确切地说)!
当我重构我的同事代码时,该项目的页面返回 502 Bad Gateway

这是我找到的:

This sometimes happens, the reason is the errors in php-fpm and xdebug (exactly)! When I refactored my colleagues code, оne page on the project returned 502 Bad Gateway
Here's what I found:

php-fpm.log


警告:[pool www] child 158对stderr说:***错误在`php-fpm:pool www':free():无效大小:0x00007f1351b7d2a0 ***
........
........
警告:[pool www] child 158在启动38.407847秒后退出信号6(SIGABRT - 核心倾销)

php-fpm.log
WARNING: [pool www] child 158 said into stderr: "*** Error in `php-fpm: pool www': free(): invalid size: 0x00007f1351b7d2a0 ***" ........ ........ WARNING: [pool www] child 158 exited on signal 6 (SIGABRT - core dumped) after 38.407847 seconds from start

我找到了导致错误的一段代码:

I found a piece of code that caused the error:

ob_start();
$result = eval("?>".$string."<"."?p"."hp return 1;");
$new_string = ob_get_clean();

但并非全部。该错误仅发生在某个状态 $ string ,乍一看,与其他状态没有区别。就我而言,一切都很简单。我删除了导致错误的代码。这不会影响网页的功能。我继续进一步调试代码。

But that is not all. The error occurred only in a certain state $string which at first glance, did not differ from the others. In my case, everything is simple. I removed the code that caused the error. This did not affect the functionality of the web page. I continued to debug the code further.

这篇关于Nginx + php-fpm:仅在xdebug服务器运行时出现错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆