我有Puma作为上游应用服务器运行,Riak作为我的后台db集群。当我发送一个请求时,map-减少了大约25K用户的数据块,并将其从Riak返回到应用程序,我在Nginx日志中得到了一个错误:
从上游读取响应头时,上游超时(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有很多超时指令。我不知道我是不是错过了一些重要的事情。任何帮助都是非常感谢的..。
发布于 2017-09-13 19:51:32
这是因为您的上游需要很长时间才能响应请求,而NGINX认为上游处理请求已经失败,因此它用错误进行响应。只需在proxy_read_timeout配置块中包含并增加location。同样的事情也发生在我身上,我在工作中对一个内部应用程序使用了1个小时的超时:
proxy_read_timeout 3600;有了这个,NGINX将等待一个小时(3600 S),它的上游返回一些东西。
发布于 2016-04-13 05:17:41
您应该始终避免增加超时,我怀疑您的后端服务器响应时间在任何情况下都是问题。
为了解决这个问题,我清除了连接保持活动标志,并按照以下答案指定了http版本:https://stackoverflow.com/a/36589120/479632。
server {
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
# these two lines here
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://localhost:5000;
}
}不幸的是,我无法解释为什么这是有效的,也无法从答案中提到的文档中破译,所以如果有人有解释的话,我会很有兴趣听到的。
发布于 2017-09-27 14:19:49
首先,通过查阅nginx错误日志文件,找出哪些上游正在减慢,并相应地调整读取时间,在我的例子中是fastCGI。
2017/09/27 13:34:03 [error] 16559#16559: *14381 upstream timed out (110: Connection timed out) while reading response header from upstream, client:xxxxxxxxxxxxxxxxxxxxxxxxx", upstream: "fastcgi://unix:/var/run/php/php5.6-fpm.sock", host: "xxxxxxxxxxxxxxx", referrer: "xxxxxxxxxxxxxxxxxxxx"因此,我必须调整服务器配置中的fastcgi_read_timeout。
location ~ \.php$ {
fastcgi_read_timeout 240;
...
}请参阅:原始员额
https://stackoverflow.com/questions/18740635
复制相似问题