nginx, falha do php5-fpm

1

Eu tenho um grande problema. Eu tenho site com nginx e php5-fpm instalado tudo funciona muito bem, mas cerca de uma vez (às vezes duas vezes, ou em todos) em um dia php5-fpm falhando. Eu não sei porque. Eu tentei muitas vezes para alterar algumas configurações, mas isso não deu nenhum efeito. Estava tudo funcionando ok, eu não mudei nada, mas um dia eu vejo erro de gateway no meu site ..

Servidor: 2GB de RAM, CPU Intel® Celeron (R) 2.66GHz, debian

Aqui está a configuração do php5-fpm:

[www]
#listen = 127.0.0.1:9000
listen.backlog = 128

listen = /var/run/php-fpm/php-fpm.sock
;listen.backlog = -1
;listen.allowed_clients = 127.0.0.1
listen.owner = www-data
listen.group = www-data
;listen.mode = 0666
user = www-data
group = www-data
pm                   = dynamic
pm.max_requests      = 400
pm.max_children      = 45
pm.start_servers     = 7
pm.min_spare_servers = 2
pm.max_spare_servers = 9

request_terminate_timeout = 0

request_slowlog_timeout = 45s
slowlog = /var/log/php-fpm/slowlog.log

catch_workers_output = yes

php_admin_value[display_errors] = 'stderr'
php_flag[display_errors] = On
php_admin_value[memory_limit] = 50M
php_admin_flag[display_startup_errors] = on
rlimit_files = 1024
rlimit_core = 0

php_admin_flag[log_errors] = on
php_admin_value[error_log]  = /var/log/php-fpm/pool.log
php_admin_value[error_reporting] = 'E_ALL & ~E_DEPRECATED'
php_admin_value[display_errors] = off
php_admin_flag[display_startup_errors] = on

Nginx cfg:

    upstream php_fpm {
        server unix:/var/run/php-fpm/php-fpm.sock;
    #server 127.0.0.1:9000;
    }

    server {
        listen   80;
        server_name  here is my domain;
        access_log  /var/log/nginx/site.access.log;
        error_log /var/log/nginx/site.error.log;

        root   /home/www/site/public;

        index index.php;


    location /status {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
    deny all;
        }
        error_page 500 = index.php;

    fastcgi_intercept_errors on;
        #try_files $uri @php_index; 

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 1d;
    log_not_found off;
    }
      location / {
        #index index.php;
        try_files $uri $uri/ /index.php;
      }

      # Deny access to sensitive files.
      location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ {
        #deny all;
        #try_files $uri $uri/ /index.php = 404;
        deny all;
      }
      location ~ \.htaccess {
        deny all;
      }

      # Rewrite rule adapted from zendapp/public/.htaccess
      if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
      }

      # PHP scripts will be forwarded to fastcgi processess.
      # Remember that the 'fastcgi_pass' directive must specify the same
      # port on which 'spawn-fcgi' runs.
      location ~ \.php$ {

    try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   php_fpm;
        fastcgi_index  index.php;


fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;



        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;


#fastcgi_send_timeout 150s;
#fastcgi_read_timeout 150s;

 #      fastcgi_buffer_size 128k;
  #      fastcgi_buffers 4 256k;
   #     fastcgi_busy_buffers_size 256k;
    #    fastcgi_temp_file_write_size 256k;
    include fastcgi_params;


    }



}

Log de erros do Nginx:

2012/12/20 04:47:01 [error] 16995#0: *158917 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:51:01 [error] 16995#0: *158952 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:53:01 [error] 16995#0: *158977 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:55:01 [error] 16995#0: *158998 upstream timed out (110: Connection timed out) while reading response header from upstream, client: server_ip, server: domain, request: "GET / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:31 [error] 16995#0: *159064 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:38 [error] 16995#0: *159066 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 173.199.120.xx, server: domain, request: "GET /d HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:42 [error] 16995#0: *159068 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:52 [error] 16995#0: *159070 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 180.76.5.xx, server: domain, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:53 [error] 16995#0: *159072 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"
2012/12/20 04:58:53 [error] 16995#0: *159074 connect() to unix:/var/run/php-fpm/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 66.249.74.xx, server: domain, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "domain"

Depuração do PHP5-fpm:

[20-gru-2012 04:58:46.960245] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:47.961359] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:48.962426] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:49.963480] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:50.964540] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:51.965601] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:52.966705] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:53.967821] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:54.968938] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:55.970062] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:56.971134] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1
[20-gru-2012 04:58:57.972193] DEBUG: pid 24382, fpm_pctl_perform_idle_server_maintenance(), line 379: [pool www] currently 45 active children, 0 spare children, 45 running children. Spawning rate 1

Atenciosamente

    
por sanrajz 20.12.2012 / 12:10

2 respostas

1

Você alcança o número máximo de crianças ativas.

Verifique seu: /var/log/php-fpm/slowlog.log para saber mais sobre scripts php lentos e tente definir:

request_terminate_timeout = 50

Atenciosamente

    
por 20.12.2012 / 12:45
1

Acredito que seu valor para pm.max_children esteja definido como 45.

Deve estar em algum lugar em /etc/php-fom.d / *. conf

pm.max_children = 45

Tente aumentar esse valor para algo mais significativo, pois você pode ver muito bem que está atingindo o limite máximo aqui.

pm.max_children = 90

Isso deve corrigir o problema.

Além disso, não creio que tenha ocorrido uma falha ao atingir o limite máximo. Algo está errado em algum lugar.

Você pode me dizer qual versão do php-fpm está usando?

    
por 20.12.2012 / 14:10