gpt4 book ai didi

NGINX:从上游读取响应 header 时上游超时(110:连接超时)

转载 作者:行者123 更新时间:2023-12-02 03:45:33 25 4
gpt4 key购买 nike

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

upstream timed out (110: Connection timed out) while reading response header from upstream

如果我在没有 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 有一堆超时指令。我不知道我是否错过了一些重要的事情。任何帮助将不胜感激......

最佳答案

发生这种情况是因为你的上游响应请求的时间太长,并且 NGINX 认为上游在处理请求时已经失败,因此它响应错误。只需在 location 配置 block 中包含并增加 proxy_read_timeout 即可。同样的事情也发生在我身上,我在工作中对内部应用程序使用了 1 小时超时:

proxy_read_timeout 3600;

这样,NGINX 将等待一个小时(3600 秒),让其上游返回一些内容。

关于NGINX:从上游读取响应 header 时上游超时(110:连接超时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18740635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com