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

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

我最近将我的 magento 从 1.5 升级到了 1.9,并且每当我将某个产品添加到购物篮时,我都会开始收到此错误:502错误的网关

没有日志条目var/日志/文件夹: 在此处输入图片描述

因此,我查看了我的 nginx 错误,发现以下条目nginx-错误日志

2015/04/09 10:58:03 [error] 15208#0: *3 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.xxx.xxx.xxx, server: dev.my-domain.co.uk, request: "POST /checkout/cart/add/uenc/aHR0cDovL2Rldi5zYWx2ZW8uY28udWsvdGludGktYmF0aC1wYWludGluZy1zb2FwLTcwbWwuaHRtbD9fX19TSUQ9VQ,,/product/15066/form_key/eYLc3lQ35BSrk6Pa/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fcgi-www-data.sock:", host: "dev.my-domain.co.uk", referrer: "http://dev.my-domain.co.uk/tinti-bath-painting-soap-70ml.html"
2015/04/09 11:04:42 [error] 15208#0: *13 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.xxx.xxx.xxx, server: dev.my-domain.co.uk, request: "POST /checkout/cart/add/uenc/aHR0cDovL2Rldi5zYWx2ZW8uY28udWsvdGludGktYmF0aC1wYWludGluZy1zb2FwLTcwbWwuaHRtbD9fX19TSUQ9VQ,,/product/15066/form_key/eYLc3lQ35BSrk6Pa/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fcgi-www-data.sock:", host: "dev.my-domain.co.uk", referrer: "http://dev.my-domain.co.uk/tinti-bath-painting-soap-70ml.html"
2015/04/09 11:05:03 [error] 15208#0: *16 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.xxx.xxx.xxx, server: dev.my-domain.co.uk, request: "POST /checkout/cart/add/uenc/aHR0cDovL2Rldi5zYWx2ZW8uY28udWsvdGludGktYmF0aC1wYWludGluZy1zb2FwLTcwbWwuaHRtbD9fX19TSUQ9VQ,,/product/15066/form_key/eYLc3lQ35BSrk6Pa/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fcgi-www-data.sock:", host: "dev.my-domain.co.uk", referrer: "http://dev.my-domain.co.uk/tinti-bath-painting-soap-70ml.html"
2015/04/09 11:12:07 [error] 15273#0: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 46.xxx.xxx.xxx, server: dev.my-domain.co.uk, request: "POST /checkout/cart/add/uenc/aHR0cDovL2Rldi5zYWx2ZW8uY28udWsvdGludGktYmF0aC1wYWludGluZy1zb2FwLTcwbWwuaHRtbD9fX19TSUQ9VQ,,/product/15066/form_key/eYLc3lQ35BSrk6Pa/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fcgi-www-data.sock:", host: "dev.my-domain.co.uk", referrer: "http://dev.my-domain.co.uk/tinti-bath-painting-soap-70ml.html"

我已经在自定义 LEMP 堆栈上安装了 magento,以下是配置:

这个错误似乎只发生在我升级后的 magento 中将特定产品添加到购物篮时,每次发生错误时,我都能看到核心.XXXXX文件(大约 350mb)公共的html文件夹。

知道为什么我的 php-fpm 会这样崩溃吗?我该如何找到原因并修复它?

以下是我在 Linux(CentOS)服务器上运行的最后条目消息命令:

php-fpm[14862]: segfault at 7fff38236ff8 ip 00000000005c02ba sp 00007fff38237000 error 6 in php-fpm[400000+325000]
php-fpm[15022]: segfault at 7fff38351ff0 ip 00000000005bf6e5 sp 00007fff38351fb0 error 6 in php-fpm[400000+325000]
php-fpm[15021]: segfault at 7fff38351ff0 ip 00000000005bf6e5 sp 00007fff38351fb0 error 6 in php-fpm[400000+325000]
php-fpm[15156]: segfault at 7fff38351ff0 ip 00000000005bf6e5 sp 00007fff38351fb0 error 6 in php-fpm[400000+325000]
php-fpm[15024]: segfault at 7fff38351ff0 ip 00000000005bf6e5 sp 00007fff38351fb0 error 6 in php-fpm[400000+325000]
php-fpm[15223]: segfault at 7fff8d1d5fd8 ip 00000000005c02ba sp 00007fff8d1d5fe0 error 6 in php-fpm[400000+325000]
php-fpm[15222]: segfault at 7fff8d1d5fd8 ip 00000000005c02ba sp 00007fff8d1d5fe0 error 6 in php-fpm[400000+325000]
php-fpm[15225]: segfault at 7fff8d1d5fd8 ip 00000000005c02ba sp 00007fff8d1d5fe0 error 6 in php-fpm[400000+325000]
php-fpm[15227]: segfault at 7fff8d1d5fd8 ip 00000000005c02ba sp 00007fff8d1d5fe0 error 6 in php-fpm[400000+325000]
php-fpm[15362]: segfault at 7fff3118afd0 ip 00000000005c0ace sp 00007fff3118afa0 error 6 in php-fpm[400000+325000]

我使用 gdb 分析了核心转储,这是我看到的前两帧:http://pastebin.com/raw.php?i=aPvB1sWv(对我来说没有多大意义)...

答案1

此类错误通常发生在服务器资源不足时,假设您正在运行最新的稳定版本php5-fpm

  1. 检查是否php5-fpm有足够的内存(没有oom-killer终止进程)

  2. 磁盘上有足够的空间

  3. 确保检查服务器上的打开文件限制。你尤其关注的是硬限制 ( -Hn):

    $ ulimit -Hn
    4096
    $ ulimit -Sn
    1024
    

检查服务器上当前打开的文件描述符的数量:

    sysctl fs.file-nr
    fs.file-nr = 1440       0       790328

现代服务器能够处理许多文件,通常ulimits设置为不必要的低值。

然后检查nginx.conf,一开始有类似这样的内容:

    worker_processes 4;
    events {
      worker_connections 1024;
    }

如果您为每个连接代理请求,则需要 2 个文件句柄。这意味着,如果连接数较多,您会很快达到限制。

nginx 有一个worker_rlimit_nofile用于限制每个工作进程打开的文件的指令(顶级指令如下worker_processes 4;):

    worker_rlimit_nofile    1024;

只需进行计算并计算当所有连接都被使用时需要打开多少个文件描述符(有点极端的情况)。还请考虑该服务器上运行的所有其他服务。

答案2

尝试增加缓冲区大小php.ini、.htaccess 或 httpd.conf(因为 PHP_INI_PERDIR)

#buffer-size
output_buffering = 65535

其次将其添加到您的 /etc/httpd/conf.d/fcgid.conf

FcgidMaxRequestLen 1073741824
FcgidOutputBufferSize 1073741824
MaxRequestLen 1073741824
  
FcgidMaxRequestsPerProcess 500
FcgidMaxProcesses 300
FcgidConnectTimeout 180
FcgidIOTimeout 2000
FcgidIdleTimeout 60
FcgidFixPathinfo 1
FcgidProcessLifeTime 60
FcgidIdleScanInterval 15
FcgidBusyTimeout 180
FcgidBusyScanInterval 30
FcgidErrorScanInterval 3
FcgidZombieScanInterval 3

相关内容