当前位置: 首页 > 知识库问答 >
问题:

使用keepalive的Nginx php fpm中出错

冯阳成
2023-03-14

我试图使用nginx php-fpm与nginx选项'保留'

在tcp端口(9000)或unix套接字( /var/run/php5-fpm.socket)上启动php-fpm时,这些错误是可见的。

这里的目的是尽可能减少Nginx-php-fpm之间新的tcp/socket连接开销,并尽可能重用连接。请注意,我将nginx'keepalive 20'保存为php fpm'pm。最大请求数=0'

有人能帮我纠正这个错误吗?

使用中的软件:

    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会议

    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 

共有3个答案

穆承运
2023-03-14

这表示php cgi子级15388不知何故从OS或php-FPM接收到SIGTERM。看见https://bugs.php.net/bug.php?id=60961

丰飞龙
2023-03-14

php-fpm有一个错误,当与nginx一起使用时,它会倒下

fastcgi_keep_conn= on;

您需要将该选项设置为关闭

姜宏盛
2023-03-14

您必须将nginxkeepalive_requests和php-fpmpm.max_requests设置为相同的值,以避免出现此错误

从上游读取响应头时,recv()失败(104:连接由对等重置)

如果这两个值不匹配,那么nginx或php-fpm最终都会关闭连接,从而触发错误。

 类似资料: