use*_*537 106 timeout nginx puma
我将Puma作为上游应用服务器运行,将Riak作为后台数据库集群运行.当我发送一个请求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;
}
}
Run Code Online (Sandbox Code Playgroud)
Nginx有一堆超时指令.我不知道我是否遗漏了一些重要的东西.任何帮助将非常感谢....
Alm*_*und 31
您应该总是避免增加超时,我怀疑您的后端服务器响应时间在任何情况下都是问题.
我通过清除连接保持活动标志并根据答案指定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;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法解释为什么这有效,并且无法从答案中提到的文档中解读它,所以如果有人有解释我会非常有兴趣听到它.
Ser*_*lez 28
发生这种情况是因为您的上游需要太多才能回答请求,NGINX认为上游已经在处理请求时失败,因此它会响应错误.只需在location中包含并增加proxy_read_timeout即可.同样的事情发生在我身上,我在工作时使用内部应用程序超时1小时:
proxy_read_timeout 3600;
Run Code Online (Sandbox Code Playgroud)
有了这个,NGINX将等待一个小时让它的上游返回一些东西.
Rub*_*nce 21
首先通过查询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"
Run Code Online (Sandbox Code Playgroud)
所以我必须在我的服务器配置中调整fastcgi_read_timeout
location ~ \.php$ {
fastcgi_read_timeout 240;
...
}
Run Code Online (Sandbox Code Playgroud)
见:原帖
我认为这个错误可能由于各种原因而发生,但它可能特定于您正在使用的模块.例如,我使用uwsgi模块看到了这一点,因此必须设置"uwsgi_read_timeout".
在您的情况下,它有助于代理中的一点优化,或者您可以使用"#time out settings"
location /
{
# time out settings
proxy_connect_timeout 159s;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffer_size 64k;
proxy_buffers 16 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_pass_header Set-Cookie;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_ignore_headers Cache-Control Expires;
proxy_set_header Referer $http_referer;
proxy_set_header Host $host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)
我建议查看error_logs,特别是在上游部分,它显示了超时的特定上游.
然后基于此,您可以调整proxy_read_timeout fastcgi_read_timeout或uwsgi_read_timeout.
还要确保您的配置已加载.
更多细节在这里Nginx上游超时(为什么以及如何修复)
正如许多其他人在这里指出的那样,增加 NGINX 的超时设置可以解决您的问题。
但是,增加超时设置可能不像这些答案所建议的那样简单。我自己也遇到了这个问题,并尝试更改/etc/nginx/nginx.conf文件中的超时设置,正如这些线程中的几乎每个人都建议的那样。这对我没有任何帮助;NGINX 的超时设置没有明显变化。现在,几个小时后,我终于设法解决了这个问题。
解决方案在这个论坛帖子中,它说你应该把你的超时设置放在/etc/nginx/conf.d/timeout.conf(如果这个文件不存在,你应该创建它)。我使用了与线程中建议的相同的设置:
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
Run Code Online (Sandbox Code Playgroud)