Nginx 在接受几个连接后丢弃连接拒绝事件

Nginx 在接受几个连接后丢弃连接拒绝事件

我已经设置 nginx 作为负载均衡器,并且 python 应用程序在负载均衡器后面的节点上运行。

我们从一个繁忙的移动网站收集事件,它会发送一个连接到我们的 api 服务器的事件。

一段时间后,我注意到下面的内容丢失。一旦我重新启动 Python 应用程序,它就会消失(一段时间后会出现错误)。

2014/02/20 23:41:51 [error] 32687#0: *40758840 connect() failed (111: Connection refused) while connecting to upstream, client: 70.196.197.177, server: _, request: "POST /1/stream/push HTTP/1.1", upstream: "fastcgi://10.67.129.106:1086", host: "api.xyz.com"

CPU/内存/网络不是瓶颈。

这是我的 nginx 配置

upstream fastcgi_uds {
        server 10.45.5.189:1081;  #Python application running on tcp ports 108*
        server 10.45.5.189:1082;
        server 10.45.5.189:1083;
        server 10.45.5.189:1084;
        server 10.45.5.189:1085;
        server 10.45.5.189:1086;
        server 10.45.5.189:1087;
        server 10.45.8.105:1081;
        server 10.45.8.105:1082;
        server 10.45.8.105:1083;
        server 10.45.8.105:1084;
        server 10.45.8.105:1085;
        server 10.45.8.105:1086;
        server 10.45.8.105:1087;
        server 10.43.154.216:1081;
        server 10.43.154.216:1082;
        server 10.43.154.216:1083;
        server 10.43.154.216:1084;
        server 10.43.154.216:1085;
        server 10.43.154.216:1086;
        server 10.43.154.216:1087;
        server 10.67.129.106:1081;
        server 10.67.129.106:1082;
        server 10.67.129.106:1083;
        server 10.67.129.106:1084;
        server 10.67.129.106:1085;
        server 10.67.129.106:1086;
        server 10.67.129.106:1087;
        server 10.230.146.53:1081;
        server 10.230.146.53:1082;
        server 10.230.146.53:1083;
        server 10.230.146.53:1084;
        server 10.230.146.53:1085;
        server 10.230.146.53:1086;
        server 10.230.146.53:1087;
        server 10.9.167.222:1081;
        server 10.9.167.222:1082;
        server 10.9.167.222:1083;
        server 10.9.167.222:1084;
        server 10.9.167.222:1085;
        server 10.9.167.222:1086;
        server 10.9.167.222:1087;

        keepalive 1024;
    }

server {
  listen 80;
  server_name _;

  error_log  /var/log/nginx/http_error.log;
  client_body_buffer_size 512k;
  client_max_body_size 10m;
  rewrite ^(.*) https://$host$1 permanent;
}

# the server directive is nginx's virtual host directive.
server {
  # port to listen on. Can also be set to an IP:PORT
    listen 443 default_server ssl;
    ssl on;
    ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!MEDIUM:!EXP:RC4+RSA:+HIGH;
    ssl_prefer_server_ciphers on;

 #keepalive_timeout  0;

  # Set the max size for file uploads to 10mb
  client_max_body_size 1m;
  client_body_buffer_size 512k;

  # sets the domain[s] that this vhost server requests for
  # server_name www.[engineyard].com [engineyard].com;
  server_name _;

  server_tokens off;

  # vhost specific access log


  # Since location blocks are usually preferred to "if"'s, this is a little better
  location ~ \.(aspx|php|jsp|cgi)$ {
    return 410;
  }
  location /1/ {
    fastcgi_pass   fastcgi_uds;
    fastcgi_keep_conn on;
    include        fastcgi_params;
        }

  location / {
    proxy_set_header  X-Real-IP  $remote_addr;

    # needed for HTTPS
    proxy_set_header Connection "";
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout 10;
    proxy_read_timeout 600;
    proxy_http_version 1.1;
#    proxy_next_upstream error;
    #proxy_pass http://upstream_nginx_servers;
#    proxy_pass http://fastcgi_uds;
  }
}

网络套接字在服务器和客户端上都受到限制。

有人可以帮忙调试这个问题吗?

答案1

由于重新启动 python 应用程序后一切恢复正常,因此问题出在该应用程序本身而不是 nginx 上。

如果您的 python 应用程序与数据库对话,也许您应该从这里开始查看。

相关内容