Access LNMP reported 502 Bad Gateway error solution

 

      LNMP : Linux + Nginx + MySQL + PHP

 

      Nginx 502 appear for many reasons, but most can be attributed to the number of resources are not enough , that the back-end PHP-FPM deal with a problem, Nginx will correct client requests sent to the back-end process php-fpm, but because php-fpm problem can not be resolved correctly process resulted in php code, eventually returned to the client 502 error.

      Nginx + PHP appear 502 bad gateway, Nginx general this is not a problem, but because of problems caused by fastcgi or php, common are the following (in fact, the best way to solve the problem themselves or go to the fastcgi and nginx errorlog):

 

1, memory_limit value of the PHP configuration file php.ini is too small.
      This must be taken if there are individual processes php program needs to occupy a great memory ..

 

2, PHP profile php-fpm.conf max_children value or the value set unreasonable max_requests

      Setting too small because there is not enough cgi process of processing the request, the General Assembly had set a while there appeared normal response, the situation for a while and so long before responding.
      Generally max_children calculated in accordance with the memory, for example, set to 128 1G 64,2G set. The self-adjusted according to actual situation.
      Also see if the current PHP FastCGI process sufficient number of command:
            netstat -anpo | grep 'PHP-cgi "| WC the -l
      if" the number of FastCGI process "closer to the actual use of the default" FastCGI number of processes, "then, Description "FastCGI process number" is not enough, need to increase.

 

3, see the service Nginx error log
      View service Nginx error log and found pstream sent too big header while reading responsecheck client_head_buffer, fastcgi_buffer_size is too small, it can be set to 32K.

 

4, too long timeout php program execution, and checks Nginx fastcgi various timeout settings.
      In nginx:
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            keepalive_timeout;

      php-fpm 中:
            request_terminate_timeout

      php.ini中:
            max_execution_time

 

5, PHP-FPM parameters in question MAX_REQUESTS
      PHP-FPM one parameter max_requests, this parameter will be turned off after a specified number of requests for each treatment most children.
      In a large number of processing requests, if the value is set too low can lead to children frequent suicide and to establish waste a lot of time,
      if all the children were almost suicidal at this time, the children will not respond to the request before the reconstruction, so there is 502.
      This value can be set larger or 0 [infinity]. (Not recommended for production environments is set to 0)

 

     If your server is complicated by very large, it can only increase the machine first, then refined by way will achieve better results; but if you did not appear concurrent 502, can generally be attributed to configuration issues, script timeout issue.

 

Guess you like

Origin www.cnblogs.com/morgan363/p/11766548.html