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

28,862

Solution 1

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;

Solution 2

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 ini_set('memory_limit', '256M') into your index.php and see if that fixes the problem.

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.

Good luck!

Solution 3

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.

Share:
28,862
Neil
Author by

Neil

Updated on July 09, 2022

Comments

  • Neil
    Neil almost 2 years

    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?

  • zmonteca
    zmonteca almost 8 years
    We also added the following, in addition to restarting both services: nginx and php5-fpm. fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300;