NGINX:大量连接超时错误

Chr*_*eid 3 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/*;
}
Run Code Online (Sandbox Code Playgroud)

Xav*_*cas 5

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

你的第二个问题:有两件事,Upgrade标题和Connection标题。

使用 websockets 时,这两个都需要传递到后端,您可以使用映射根据原始请求标头(即,如果它是 websocket 连接handhaske 或标准 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;
    }

}
Run Code Online (Sandbox Code Playgroud)