我将Puma作为上游应用服务器运行,Riak作为后台数据库集群运行。当我发送一个请求,映射减少了大约25K用户的数据块,并从Riak返回到应用程序,我在Nginx日志中得到一个错误:

upstream读取时超时(110:连接超时) 来自上游的响应头

如果我直接查询我的上游没有nginx代理,同样的请求,我得到所需的数据。

一旦代理被放入Nginx超时就会发生。

**nginx.conf**

http {
    keepalive_timeout 10m;
    proxy_connect_timeout  600s;
    proxy_send_timeout  600s;
    proxy_read_timeout  600s;
    fastcgi_send_timeout 600s;
    fastcgi_read_timeout 600s;
    include /etc/nginx/sites-enabled/*.conf;
}

**virtual host conf**

upstream ss_api {
  server 127.0.0.1:3000 max_fails=0  fail_timeout=600;
}

server {
  listen 81;
  server_name xxxxx.com; # change to match your URL

  location / {
    # match the name of upstream directive which is defined above
    proxy_pass http://ss_api; 
    proxy_set_header  Host $http_host;
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_cache cloud;
    proxy_cache_valid  200 302  60m;
    proxy_cache_valid  404      1m;
    proxy_cache_bypass $http_authorization;
    proxy_cache_bypass http://ss_api/account/;
    add_header X-Cache-Status $upstream_cache_status;
  }
}

Nginx有一堆超时指令。我不知道我是不是错过了什么重要的东西。任何帮助将高度赞赏....


当前回答

我们在保存内容(自定义内容类型)时遇到了超时错误。通过添加以上所有超时,http客户端配置到600s,并增加php进程的内存到3gb来修复这个问题。

其他回答

我们在保存内容(自定义内容类型)时遇到了超时错误。通过添加以上所有超时,http客户端配置到600s,并增加php进程的内存到3gb来修复这个问题。

从我们这边来看,它使用spdy代理缓存。当缓存过期时,我们得到这个错误,直到缓存被更新。

请检查上游服务器的keepalive_timeout。

我得到了一个类似的问题:随机502,连接重置由nginx日志中的peer错误,发生在服务器负载过重时。最终发现这是由nginx'和upstream'(在我的例子中是gunicorn)的keepalive_timeout值不匹配引起的。Nginx的速度是75秒,仅在几秒钟内就上升了。这导致上游有时会超时并断开连接,而nginx不明白为什么。

提高上游服务器的值以匹配nginx的one解决了这个问题。

我建议查看error_logs,特别是上游部分,其中显示了超时的特定上游。

然后在此基础上,您可以调整proxy_read_timeout, fastcgi_read_timeout或uwsgi_read_timeout。

还要确保您的配置已加载。

更多细节在这里Nginx上游超时(为什么和如何修复)

新增一行配置到location或nginx.conf,例如: proxy_read_timeout 900年代;