Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid getting a 502 Gateway Error while restarting php-fpm?

Tags:

php

nginx

When restarting the php-fpm service on my Linux system, the PHP CGI process take a while to shutdown completely. Until it does, trying to start a new PHP CGI instance fails because port 9000 is still held by the terminating process. Accessing the site during this time results in a 502 Gateway Error, which I'd like to avoid.

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

like image 227
NeilJiang Avatar asked Mar 02 '11 07:03

NeilJiang


1 Answers

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

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

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

like image 117
CyberDem0n Avatar answered Oct 17 '22 18:10

CyberDem0n