Nginx error recv() failed (104: Connection reset by peer)


Nginx error recv() failed (104: Connection reset by peer)

自从几天前,我在我的服务器上得到一些错误。我使用CentOS 6.5和Parallels 12.0.18, Apache服务器提供动态内容,Nginx作为代理提供静态内容。

首先,我得到以下错误:

[error] 29951#0: *5138862 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 89.7.24.108, server: , request: "GET /page/2/ HTTP/1.1", upstream: "http://ip:7080/page/2/", host: "domain.es", referrer: "http://domain.es/"

然后,我改变了一些配置,比如在我的"httpd.conf"文件中增加MaxClients,并将这一行添加到我的/etc/nginx/conf.d/timeout.conf文件中:

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

一切似乎都很好,直到我再次得到相同的错误,以及一个新的:

[error] 15228#0: *130292 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 89.130.25.154, server: domain.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:7080/", host: "domain.com"

我在同一台服务器上有两个不同的网站。这就是为什么你在这里看到两个不同的主机。

问题是:当我得到这些错误时,我得到了一个"502坏网关",服务器变得很慢,我甚至不能使用SSH终端登录。我只能通过重置httpd服务来暂时修复它。

我知道还有其他类似的主题,但我发现的都是PHP-FPM的问题,我不使用。

下面是我的Nginx配置文件:用户nginx;worker_processes 16;
error_log  /var/log/nginx/error.log;
events {
    worker_connections  1024;
}
http {
server_names_hash_max_size 2048;
server_names_hash_bucket_size 512;
server_tokens off;
include    mime.types;
default_type  application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout  10;
# Gzip on
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_buffers 4 32k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_disable "MSIE [1-6]'.";
# Other configurations
ignore_invalid_headers on;
client_max_body_size    8m;
client_header_timeout  3m;
client_body_timeout 3m;
#send_timeout     3m;
connection_pool_size  256;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
request_pool_size  4k;
output_buffers   4 32k;
postpone_output  1460;
# Cache most accessed static files
open_file_cache          max=10000 inactive=10m;
open_file_cache_valid    2m;
open_file_cache_min_uses 1;
open_file_cache_errors   on;
# virtual hosts includes
include "/etc/nginx/conf.d/*.conf";
}
这是我的Nginx vhost文件:服务器{
server_name domain.es;
server_name www.domain.es;
server_name ipv4.domain.es;
client_max_body_size 128m;
root "/var/www/vhosts/domain.es/httpdocs";
access_log "/var/www/vhosts/system/domain.es/logs/proxy_access_log";
error_log "/var/www/vhosts/system/domain.es/logs/proxy_error_log";
if ($host ~* ^www.domain.es$) {
    rewrite ^(.*)$ http://domain.es$1 permanent;
}
location / {
    proxy_pass http://82.194.74.41:7080;
    proxy_set_header Host             $host;
    proxy_set_header X-Real-IP        $remote_addr;
    proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
    access_log off;
}
location @fallback {
    proxy_pass http://ip:7080;
    proxy_set_header Host             $host;
    proxy_set_header X-Real-IP        $remote_addr;
    proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
    access_log off;
}
location ~ ^/plesk-stat/ {
    proxy_pass http://ip:7080;
    proxy_set_header Host             $host;
    proxy_set_header X-Real-IP        $remote_addr;
    proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
    access_log off;
}
location ~ ^/(.*'.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|swf|tar|tgz|txt|wav|xls|xlsx|zip))$ {
    access_log off;
    expires 7d;
    add_header Cache-Control public;
 try_files $uri @fallback;
}
include "/var/www/vhosts/system/domain.es/conf/vhost_nginx.conf";
}

和一些配置变量我使用Apache (httpd.conf):

<IfModule prefork.c>
StartServers      14
MinSpareServers    8
MaxSpareServers   14
ServerLimit      1000
MaxClients       1000
MaxRequestsPerChild  2000
</IfModule>

提前非常感谢!

在我的情况下,php扩展丢失了,在我关闭它之后,它恢复了!检查/var/log/messages是否有segfault

似乎你的Apache比你的Nginx更忙。当Nginx收到一些请求,但是Apache无法处理时,你会得到'502 Bad Gateway',这意味着Apache拒绝为Nginx工作。

尝试减少'worker_connections'和'worker_processes',增加'MaxClients', 'ServerLimit'

确定Worker_connections * worker_processes <数&>

在最近的一个案例中,我看到95%的请求都记录了这个错误,但是web服务器和应用服务器几乎都是空闲的,只有几个连接打开。其余5%成功。

原来,我们友好的网络同事在web和应用服务器之间配置了一个IPS设备,当流量增加时,它开始恢复并断开连接,因为它认为发生了暴力攻击。假阳性。所以与Nginx或Apache无关,但重新配置IPS解决了这个问题。

跟踪代码以检测是否有类似于" opendir ";没有"closedir".