NGINX:大量连接超时错误

NGINX:大量连接超时错误

我经常遇到这个错误:

2014/11/26 21:01:30 [错误] 3475#0: *4028 上游读取响应头时超时(110:连接超时)

这是我的配置:

user www-data;
pid /run/nginx.pid;
worker_processes 2;
worker_rlimit_nofile 16384;

events {
  worker_connections    4096;
  use                   epoll;
  multi_accept          on;
}

http {

  sendfile              on;
  tcp_nopush            on;
  tcp_nodelay           on;
  keepalive_timeout     65;

  # free up connection after client stops responding...
  reset_timedout_connection on;

  # If the client stops reading data, free up the stale client connection after this much time. Default 60.
  # send_timeout          2;


  types_hash_max_size   2048;

  server_names_hash_bucket_size 256;
  # server_name_in_redirect off;

  include               /etc/nginx/mime.types;
  default_type          application/octet-stream;

  ssl_protocols         TLSv1 TLSv1.1 TLSv1.2;  # don’t use SSLv3 ref: POODLE
  ssl_ciphers           "AES256+EECDH:AES256+EDH";

  access_log            /var/log/nginx/access.log;
  error_log             /var/log/nginx/error.log;

  ##
  # Gzip Settings
  ##

  gzip                  on;
  gzip_vary             on;
  gzip_min_length       10240;
  gzip_proxied          expired no-cache no-store private auth;
  gzip_types            text/plain text/css text/xml text/javascript application/x-javascript application/xml;
  gzip_disable          "MSIE [1-6]\.";
  ##
  # general proxy settings
  ##
  proxy_cache_path      /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
  proxy_temp_path       /var/tmp;
  proxy_intercept_errors on;

  include               /etc/nginx/conf.d/*.conf;
  include               /etc/nginx/sites-enabled/*;
}

答案1

前一个问题的解决方案:增加proxy_read_timeout或者检查为什么你的后端没有及时应答。

你的第二个问题:有两个,Upgrade头和Connection头。

使用 websockets 时,这两者都需要传递给后端,并且您可以使用映射根据原始请求标头(即,它是 websocket 连接握手还是标准 HTTP 流量)更改值。后端必须Upgrade使用 HTTP 回复标头101。然后 nginx 将进入在请求源和后端之间建立隧道的特定情况。

这种情况在官方文档

http {

    map $http_upgrade $connection_upgrade {
        default     upgrade;
        ''          close;
    }

}

server {

   ...

   location /foo/ {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }

}

相关内容