简体   繁体   中英

Drupal + Nginx + Php-cgi : 502 Bad Gateway error

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.

Did anyone else run into this type of issue? What are the possible suspects?

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

add the following lines into http section :

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

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.

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 into your index.php and see if that fixes the problem. 放入index.php并查看是否可以解决问题,这很容易解决。

Also, can you load stand alone PHP files that don't involve Drupal? Put putting into a file called info.php and try hitting that and see what happens. 到一个名为info.php的文件中,尝试点击它,看看会发生什么。

Good luck!

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 .

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-fpm it won't.

increase your memory limit and it will be fixed. ini_set('memory_limit', '256M');

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.

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.

If you have firePHP disable it. Big headers causes problems while nginx comunication with php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM