Drupal + Nginx + Php-cgi:502 错误网关错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1514576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drupal + Nginx + Php-cgi : 502 Bad Gateway error
提问by Neil
We are running Drupal 5.x on Nginx with php-fastcgi. Things were working fine for a while. All of a sudden, we (users) are running into 502 Bad Gateway error. Restarting PHP-cgi, nginx.. rebooting machine etc did not help.
我们正在使用 php-fastcgi 在 Nginx 上运行 Drupal 5.x。事情运行良好有一段时间。突然之间,我们(用户)遇到了 502 Bad Gateway 错误。重新启动 PHP-cgi、nginx.. 重新启动机器等没有帮助。
Did anyone else run into this type of issue? What are the possible suspects?
有没有其他人遇到过这种类型的问题?可能的嫌疑人是什么?
回答by Govind Totla
Today I was getting “502 Bad Gateway” on a CI project , after digging into the problem I found out it is a problem of nginx fastcgi buffers , here is how to fix it : open /etc/nginx/nginx.conf
今天我在一个 CI 项目上遇到了“502 Bad Gateway”,在深入研究这个问题之后我发现这是一个 nginx fastcgi 缓冲区的问题,这里是如何修复它:打开 /etc/nginx/nginx.conf
add the following lines into http section :
将以下行添加到 http 部分:
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
回答by Douglas Muth
502 errors are usually caused when PHP freaks out for some reason. The first thing you should do is check all of your logfiles. That includes system stuff in /var/log/ and the nginx logs.
502 错误通常是在 PHP 由于某种原因而崩溃时引起的。您应该做的第一件事是检查所有日志文件。这包括 /var/log/ 和 nginx 日志中的系统内容。
If you haven't made any recent changes and the problem just started happening for no apparent reason, PHP may be running out of memory. I know when it happens as an Apache module it gives a blank screen--wouldn't be surprised if a 502 error happened under nginx and the FastCGI interface. That's easy to fix by putting ini_set('memory_limit', '256M')into your index.php and see if that fixes the problem.
如果您最近没有进行任何更改并且问题刚刚开始发生并且没有明显的原因,则 PHP 可能内存不足。我知道当它作为 Apache 模块发生时,它会给出一个空白屏幕——如果在 nginx 和 FastCGI 接口下发生 502 错误,我不会感到惊讶。通过将ini_set('memory_limit', '256M')放入 index.php 并查看是否可以解决问题,这很容易解决。
Also, can you load stand alone PHP files that don't involve Drupal? Put putting <?php phpinfo(); ?>into a file called info.php and try hitting that and see what happens.
另外,您可以加载不涉及 Drupal 的独立 PHP 文件吗?把<?php phpinfo(); ?>进入一个名为 info.php 的文件,然后尝试点击它,看看会发生什么。
Good luck!
祝你好运!
回答by Hana J. Chang
I got this error as well and I eventually disable all modules (non-core) and enable them one by one to see what caused the error.
我也遇到了这个错误,我最终禁用了所有模块(非核心)并一一启用它们以查看导致错误的原因。
Here's a easy way to disable all non-core modules.
这是禁用所有非核心模块的简单方法。
回答by user2239845
increase your memory limit and it will be fixed. ini_set('memory_limit', '256M');
增加您的内存限制,它将被修复。ini_set('memory_limit', '256M');
回答by kratos
It is because you probably upgraded to PHP 5.5 and therefore you now are using opcode cache which you may have enabled twice. That is check php.ini and also opcache.ini.
这是因为您可能已升级到 PHP 5.5,因此您现在正在使用可能已启用两次的操作码缓存。即检查 php.ini 和 opcache.ini。
回答by Joshua
If the problem just started.. Read above.. if the server is new just setup, try this command to see if it's even listening on it's port
如果问题刚刚开始.. 阅读上面.. 如果服务器是新设置的,请尝试此命令以查看它是否甚至在侦听其端口
netstat -lpn | grep ":9000"
If course you could have setup fast-cgi to work on a different port, so just replace the port 9000 in that statement with what ever port you're looking for.. If nothing continues to show up, likely nothing is listening on that port and you need to fix that problem first.
如果您当然可以设置 fast-cgi 以在不同的端口上工作,那么只需将语句中的端口 9000 替换为您正在寻找的端口。你需要先解决这个问题。
回答by nerkn
If you have firePHP disable it. Big headers causes problems while nginx comunication with php
如果你有 firePHP 禁用它。nginx 与 php 通信时,大标题会导致问题
回答by rojoca
Usually when I have come across this it has been a fatal error in PHP somewhere. Have a look at your PHP-cgi log to see if it is in there. There should be something in the nginx log like this: 104: Connection reset by peer. Depending on your setup this (sorry, link dead)might help but if you're using php-fpmit won't.
通常,当我遇到这种情况时,它是 PHP 中某个地方的致命错误。查看你的 PHP-cgi 日志,看看它是否在那里。应该有什么东西在nginx的日志是这样的:104: Connection reset by peer。根据您的设置,这(抱歉,链接失效)可能会有所帮助,但如果您使用的是php-fpm,则不会。

