首页 文章

使用keepalive和fastcgi_keep_conn打开Nginx php-fpm时出错

提问于
浏览
1

我正在尝试使用Nginx php-fpm与nginx选项'keepalive'和'fastcgi_keep_conn on'来保持tcp连接在它们之间保持活动状态,但在服务几百个请求后面临错误 "104: Connection reset by peer" .

在tcp端口(9000)或unix socket(/var/run/php5-fpm.socket)上启动php-fpm可以看到这些错误 .

这里的内容是尽可能减少Nginx php-fpm之间的新tcp / socket连接开销,并尽可能地重用连接 . 请注意,我保持nginx'keepalive 20',其中php-fpm'pm.max_requests = 0'和'pm.start_servers = 50' .

有人可以帮我解决这个错误吗?

使用的软件:

nginx version: nginx/1.4.7
    php-fpm version: 5.4.25 / 5.6.6

PHP-FPM错误日志条目:

WARNING: [pool www] child 15388 exited on signal 15 (SIGTERM) after 2245.557110 seconds from start 
    NOTICE: [pool www] child 18701 started

Nginx错误:

用php-fpm监听端口 9000

[error] 32310#0: *765 readv() failed (104: Connection reset by peer) while reading upstream, client: 10.10.133.xx, server: 192.168.28.xxx, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "10.10.133.xxx"

用php-fpm监听套接字 /var/run/php5-fpm.socket

[error] 14894#0: *383 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.10.133.xx, server: 192.168.28.xxx, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.socket:", host: "10.10.133.xxx"

以下是nginx vhost conf

upstream fastcgi_backend {
        server 127.0.0.1:9000;
        #server unix:/var/run/php5-fpm.socket;
        keepalive 30;
    }
    server {
            listen  80;
            server_name 10.10.xxx.xxx;
            access_log /tmp/ngx_access_80.log;
            error_log /tmp/ngx_error_80.log;

            location ~ \.php$ {
                root           /var/www/test/;
                include        fastcgi_params;
                fastcgi_pass   fastcgi_backend; //upstream set above
                fastcgi_keep_conn on; #Test for keepalive connection to php-fpm
                fastcgi_buffer_size 16k;
                fastcgi_buffers 4 16k;
            }
    }

以下是php-fpm.conf

[global]
    pid = /var/run/php-fpm-9000.pid
    error_log = /var/log/php-fpm-9000.log

    [www]
    listen = 0.0.0.0:9000
    user = daemon
    group = daemon
    rlimit_files = 60000

    pm = dynamic
    pm.max_requests = 0

    pm.max_children = 500
    pm.start_servers = 50
    pm.min_spare_servers = 40
    pm.max_spare_servers = 90

2 回答

  • -1

    php-fpm 存在一个错误,当与nginx一起使用时会出现问题

    fastcgi_keep_conn= on;
    

    您需要将该选项设置为 off .

  • -2

    这表明php-cgi子15388已从OS或PHP-FPM收到SIGTERM . 见https://bugs.php.net/bug.php?id=60961

相关问题