Monday, March 27, 2017

Overcoming 502 Bad Gateway on Nginx

in this article I will discuss " Overcoming 502 Bad Gateway on Nginx " 

This time the problem I experienced was on the WordPress website using Nginx and there in front of CloudFlare, but the reason for the emergence of HTTP 502 Bad Gateway error. 

If you see a white page Nginx with the following error message means the same case :

  • 502 Bad Gateway
  • 502 Proxy Error
  • 502 Bad Gateway NGINX
  • 502 Service Temporarily Overloaded
  • Error 502
  • HTTP 502
  • HTTP Error 502 – Bad Gateway
Before we discuss the solution is then obliged us to understand what the purpose of this error message. So Bad Gateway that means is the gate / driveway problematic. The point is that the service or application that receives and processes requests from Nginx can not handle it. It usually occurs in PHP-FPM and became my base in the discussion of this case.



Restart PHP-FPM

The solution is easy and fast, you just type:

service php5-fpm restart " 

This could be said to be temporary because we are not trying to find out and fix the problem. After servicenya active again you must check the contents of the error logs PHP-FPM what the problem to be diagnosed.



Make sure your PHP-FPM listening to right

There are 2 kinds of ways services PHP-FPM listen to and serve the request, via a socket or IP address. Please check the configuration (named www.conf) and make sure the contents one of the following, or you exchange: 
listen = /var/run/php5-fpm.sock "

                              or

        " listen = 127.0.0.1:xxxx "

After that the restart PHP-FPM.

Check the rights of PHP-FPM AKSes

There are times when we forget governs how files - file PHP-FPM service will be used by Nginx. Just make sure it can communicate:

  • Check php.ini and www.conf contents in user and group parts are compatible with the existing Nginx configuration.
  • Is /var/run/php5-fpm.sock file can be used Nginx?
  • Including the / var / lib / php please verify.

Turn off the APC or try another caching system in PHP

APC (Alternative PHP Cache) function is to create a cache of code - PHP code that is executed so that the next process requiring the same functions will be faster processing. But sometimes these features result in error 502, I suggest that first try disabling it.

I recommended replacing the alternative to it. The consideration is the old system and has been replaced by PHP OPcache, try using a new one and formally included in PHP version 5.5 and above.

Increase the buffer size and timeout on Nginx configuration

So please edit nginx.conf and place the following code in the block http {}:

http { fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; }

Functions that Nginx process data with a larger container in memory so it does not need to be stored in the hard disk while. Also when the process is timed to avoid direct longer be considered a failure.

So first up the discussion here, I just know some of the above solutions. And I just realized though the title Nginx but the solution is 4 the tooling - tweaking PHP-FPM and the only one whose dealings with Nginx.
Share:
Comments
0 Comments

0 comments:

Post a Comment

click banner for more

Translate