nginx,php5-fpm 崩溃

nginx,php5-fpm 崩溃

我有一个大问题。我的网站安装了 nginx 和 php5-fpm,一切运行良好,但一天内 php5-fpm 崩溃一次(有时两次,或根本不崩溃)。我不知道为什么。我多次尝试更改某些配置,但没有任何效果。一切正常,我没有更改任何内容,但有一天我看到我的网站上出现网关错误。

服务器:2GB RAM,Intel(R) Celeron(R) CPU 2.66GHz,debian

这是 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 配置:

    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;


    }



}

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"

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

此致

答案1

您已达到活跃孩子的最大数量。

检查:/var/log/php-fpm/slowlog.log 以获取有关慢速 php 脚本的一些提示,并尝试设置:

request_terminate_timeout = 50

此致

答案2

我相信您的 pm.max_children 值设置为 45。

它应该位于 /etc/php-fom.d/*.conf 的某个位置

下午.max_children = 45

尝试将该值增加到更重要的值,因为您可以清楚地看到您已达到此处的上限。

下午.max_children = 90

这应该可以解决这个问题。

另外,我认为它不应该在达到最大限制后崩溃。肯定是哪里出了问题。

您能告诉我您使用的是哪个版本的 php-fpm 吗?

相关内容