在 Nginx 中使用 Phalcon 和 jQuery 提交时出现 502 Bad Gateway 错误

发布于 2025-01-18 09:57:48 字数 565 浏览 1 评论 0原文

我在使用 Phalcon 4.0.x 框架解决 NGINX 服务器上的 502 错误时遇到一些问题。特别是在将 Ajax 数据发送到 PHP 控制器的表单上。这些似乎没有到达,但 Ajax 正在工作。

我探索了几种替代方案但没有成功。

NGINX 配置如下:

location / {
        # Matches URLS $_GET['_url']
        try_files $uri $uri/ /index.php?_url=$uri&$args;
        #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        #add_header 'Access-Control-Allow-Headers' 'X-Request-With' always;
        #add_header X-Content-Type-Options nosniff;
    }

我检查了 jQuery 是否正常工作并且 我更改了 NGINX 配置文件并测试了 PHP-FPM 是否正常工作。

I'm having some trouble resolving a 502 error on an NGINX server using the Phalcon 4.0.x Framework. Specifically on forms that send Ajax data to the PHP controller. These do not seems to arrive, but the Ajax it is working.

I have explored several alternatives without success.

The NGINX configuration is as follows:

location / {
        # Matches URLS $_GET['_url']
        try_files $uri $uri/ /index.php?_url=$uri&$args;
        #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
        #add_header 'Access-Control-Allow-Headers' 'X-Request-With' always;
        #add_header X-Content-Type-Options nosniff;
    }

I checked if jQuery is working and
I changed NGINX configuration file and tested if PHP-FPM es working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2025-01-25 09:57:48

502错误通常意味着Nginx无法联系上游PHP服务器。根据你所说的,我相信你的正常解决方案是有效的。您可以通过简单地将 Ajax 请求上的 index.php 更改为仅 echo“hello world” 来确认这一点; exit; 并确认其正常工作。

也就是说,我确实在另一个实例中看到了 502 错误。即处理过程中发生错误,导致分段错误或堆栈错误。弄清楚这一点有点棘手,但您可以做几件事。第一个是通过使用 log_errors = onerror_log = /temp/php.log 配置 php 来启用日志记录,并查看输出是什么。另一种选择(在我看来通常更好)是使用 xdebug 逐行单步执行代码,直到找到错误。您还可以在 xdebug 中使用分析或跟踪,但我个人发现单步执行代码最容易找到直接原因。一旦找到原因,就可以从那里开始解决问题。

我想说的是,如果最终是段错误,则需要使用gdb来调试,这里不再赘述。

A 502 error usually means that Nginx is unable to contact the upstream PHP server. Based off what you’ve said, I believe your normal resolution is working. You can confirm this by simply changing your index.php on an Ajax request to have just echo “hello world”; exit; and confirm it working.

That said I do see a 502 error in one other instance specifically. That is when an error is occurring in the processing that causes a segmentation fault or stacking errors. This is a bit trickier to figure out but there are several things you can do. The first is enable logging by configuring php with log_errors = on and error_log = /temp/php.log And see what the output is. The alternative, and typically better in my opinion is using xdebug to step the code line by line until you find the error. You can also use profiling or tracing in xdebug, but I personally find stepping the code the easiest to get to the direct cause. Once you find the cause, you can go from there in resolving it.

I will say this, if it ends up being a seg fault, you will need to use gdb to debug, which I will not go into here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文