Error de Nginx + php-fpm "504 Gateway Time-out" con carga casi nula (en un servidor de prueba)

Error de Nginx + php-fpm "504 Gateway Time-out" con carga casi nula (en un servidor de prueba)

Después de depurar durante 6 horas, abandono esto :|

Tenemos nginx+php-fpm+mysql en LAN con casi 100 wordpress (creados y utilizados por diferentes diseñadores/desarrolladores, todos trabajando en la configuración de prueba de wordpres)

Estamos usando nginx sin problemas desde hace mucho tiempo.

Hoy, de repente, nginx comenzó a devolver "504 Gateway Time-out" de la nada...

Revisé el registro de errores de nginx para un host virtual...

2010/09/06 21:24:24 [error] 12909#0: *349 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *349 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:11 [error] 12909#0: *443 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 21:25:12 [error] 12909#0: *443 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:08:32 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:33 [error] 12909#0: *1025 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:09:40 [error] 12909#0: *1064 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:44 [error] 12909#0: *1313 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"
2010/09/06 22:24:53 [error] 12909#0: *1313 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.0.1, server: rahul286.rtcamp.info, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "rahul286.rtcamp.info"

Mientras ejecutaba php-fpm en el puerto 9000 a través del modo TCP, ejecuté "netstat | grep 9000" y noté algo inusual... (Pegando aquí el resultado parcial para facilitar la lectura)

tcp        9      0 localhost:9000          localhost:36094         CLOSE_WAIT  14269/php5-fpm  
tcp        0      0 localhost:46664         localhost:9000          FIN_WAIT2   -               
tcp     1257      0 localhost:9000          localhost:36135         CLOSE_WAIT  -               
tcp     1257      0 localhost:9000          localhost:36125         CLOSE_WAIT  -               
tcp        9      0 localhost:9000          localhost:36102         CLOSE_WAIT  14268/php5-fpm  
tcp        0      0 localhost:46662         localhost:9000          FIN_WAIT2   -               
tcp      745      0 localhost:9000          localhost:46644         CLOSE_WAIT  -               
tcp        0      0 localhost:46658         localhost:9000          FIN_WAIT2   -               
tcp     1265      0 localhost:9000          localhost:46607         CLOSE_WAIT  -               
tcp        0      0 localhost:46672         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1257      0 localhost:9000          localhost:36119         CLOSE_WAIT  -               
tcp     1265      0 localhost:9000          localhost:46613         CLOSE_WAIT  -               
tcp        0      0 localhost:46646         localhost:9000          FIN_WAIT2   -               
tcp     1257      0 localhost:9000          localhost:36137         CLOSE_WAIT  -               
tcp        0      0 localhost:46670         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1265      0 localhost:9000          localhost:46619         CLOSE_WAIT  -               
tcp     1336      0 localhost:9000          localhost:46668         ESTABLISHED -               
tcp        0      0 localhost:46648         localhost:9000          FIN_WAIT2   -               
tcp     1336      0 localhost:9000          localhost:46670         ESTABLISHED -               
tcp        9      0 localhost:9000          localhost:36108         CLOSE_WAIT  14274/php5-fpm  
tcp     1336      0 localhost:9000          localhost:46684         ESTABLISHED -               
tcp        0      0 localhost:46674         localhost:9000          ESTABLISHED 12909/nginx: worker
tcp     1336      0 localhost:9000          localhost:46666         ESTABLISHED -               
tcp     1257      0 localhost:9000          localhost:46648         CLOSE_WAIT  -               
tcp     1336      0 localhost:9000          localhost:46678         ESTABLISHED -               
tcp        0      0 localhost:46668         localhost:9000          ESTABLISHED 12909/nginx: wo             

Hay muchos pares "CLOSE_WAIT" y "FIN_WAIT2" como se resalta a continuación (en el resultado anterior):

tcp     1337      0 localhost:9000          localhost:46680         CLOSE_WAIT  -               
tcp        0      0 localhost:46680         localhost:9000          FIN_WAIT2   -

Tenga en cuenta el puerto 46680 arriba.

Habilité el registro de errores de consultas lentas de MySQL, pero no funcionó.

A partir de ahora reiniciando php5-fpm cada minuto a través de un cronjob (ver comando a continuación) manteniendo todo funcionando "sin problemas", pero odio el patchwork y quiero resolver esto...

1 * * * * service php5-fpm restart > /dev/null

Busqué mucho en Google y no obtuve ayuda. Como se mencionó, este es un servidor de prueba en LAN, la carga de la CPU nunca supera 0.10 y el uso de la memoria también está por debajo del 25% (el sistema tiene 2 GB de RAM y un servidor ubuntu instalado). Entonces, si le resulta confuso ayudarme, por favor. al menos deja una pista.

Gracias de antemano por la ayuda.

-Rahul

(nota - esto es volver a publicar -http://forum.nginx.org/read.php?11,127694)

Actualización: encontré la respuesta, que se publica a continuación.

Respuesta1

Encontré la respuesta en mi publicación en el foro de nginx:http://forum.nginx.org/read.php?2,127854

La respuesta, en mi caso, es establecer:

request_terminate_timeout=30s

en la configuración de php-fpm (normalmente /etc/php5/fpm/php-fpm.conf)

Tenga en cuenta que también puede utilizar valores distintos de 30.

Lo usé para hacer coincidir mi valor en php.iniel archivo principal que es:

max_execution_time = 30

Gracias a todos. :-)

Respuesta2

Así resolvió mi problema:

realice los siguientes cambios en /etc/nginx/nginx.conf en la sección http {

proxy_connect_timeout  600s;
proxy_send_timeout  600s;
proxy_read_timeout  600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;

y luego reinicie nginx

/etc/init.d/nginx reiniciar

Respuesta3

Si está utilizando php 5.3, aumente el trabajo pendiente.

Si está utilizando PHP 5.2, actualice el parche para aumentar el tamaño del trabajo pendiente de 128.

Además, utilice un socket Unix en lugar de un socket TCP. unix:/tmp/php5-cgi.sock (o la ruta correspondiente)

Respuesta4

en mi caso (mismo mensaje de error de nginx), algunos scripts php problemáticos no terminan de ejecutarse y esperan algo, lo que da como resultado que no haya más hijos php5-fpm para que nginx los seleccione.

arreglar:

  1. Agregue el límite de tiempo de ejecución. Otros lo mencionaron en esta publicación. request_terminate_timeout=30s
  2. aumentar el número de hijos. y todo funcionó a las mil maravillas. pm.max_spare_servers=16 pm.min_spare_servers=2

ahora todo funcionó a las mil maravillas.

información relacionada