How can I avoid getting a Gateway 502 error when restarting php-fpm?

When restarting the php-fpm service on my Linux system, the PHP CGI process takes some time to shut down completely. Until this happens, an attempt to start a new instance of CGI PHP will fail because port 9000 is still held by the terminating process. Access to the site during this time leads to a 502 Gateway error, which I would like to avoid.

How can I restart php-fpm smoothly without getting this error?

+6
php nginx
source share
1 answer

Run two instances of php-fpm, describe it in one upstream section.

  upstream fast_cgi {
         server localhost: 9000;
         server localhost: 9001 backup;
     }

Modify nginx.conf to use fastcgi_pass fast_cgi; . After that, if you restart one instance, nginx will process the request through the second instance of php-fpm.

+6
source share

All Articles