Nginx upstream 长独角兽请求超时
Nginx upstream timed out for long unicorn request
我有一个 Rails 应用程序由 nginx/unicorn 提供,它有一个特定的请求可能需要 2-3 分钟,因为它会生成多个 PDF 并将它们添加到一个 zip 文件中,并且使用 send_data 允许客户端一次下载多个报告。
最初我的独角兽工人在 30 秒后被杀,所以我增加了 unicorn.rb 文件中的超时时间。现在请求在 60 秒而不是 30 秒后收到 504 错误。所以我的独角兽工人被杀了,但 nginx 超时了。
这是我的 nginx error_log 中的错误消息:
upstream timed out (110: Connection timed out) while reading response header from upstream
我尝试增加所有有意义的 nginx 超时设置,但在 service nginx restart
之后请求仍然超时。
这是我的 nginx.conf 和 sites-enabled/default
/***nginx.conf***/
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300s;
client_header_timeout 300s;
client_body_timeout 300s;
send_timeout 300s;
types_hash_max_size 2048;
}
/***sites-enabled/default***/
upstream app {
unix:[PATH]/unicorn.sock fail_timeout=120s;
}
server {
listen 80;
root [PATH];
server_name www.[URL].com [URL].com;
proxy_read_timeout 600s;
try_files $uri/index.html $uri @app;
access_log /var/log/nginx/APP_access.log combined;
error_log /var/log/nginx/APP_error.log;
location @app {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 75;
}
谁能告诉我为什么 nginx 在 60 秒后仍然超时?
我可能已经通过重启服务器解决了这个问题。更改我的任何 nginx 文件后,我会 运行 service nginx reload
或 service nginx restart
但我想这实际上并没有重置我正在扩展的超时设置。
现在的问题是我不能 100% 确定我扩展的许多超时设置中的哪一个是我需要的。我可能会倒过来弄清楚这个,但我猜这是代理设置之一。
正确的解决方案仍然是(如@house9 所说)实际设置后台作业,但这是对我的问题的修复。
我有一个 Rails 应用程序由 nginx/unicorn 提供,它有一个特定的请求可能需要 2-3 分钟,因为它会生成多个 PDF 并将它们添加到一个 zip 文件中,并且使用 send_data 允许客户端一次下载多个报告。
最初我的独角兽工人在 30 秒后被杀,所以我增加了 unicorn.rb 文件中的超时时间。现在请求在 60 秒而不是 30 秒后收到 504 错误。所以我的独角兽工人被杀了,但 nginx 超时了。
这是我的 nginx error_log 中的错误消息:
upstream timed out (110: Connection timed out) while reading response header from upstream
我尝试增加所有有意义的 nginx 超时设置,但在 service nginx restart
之后请求仍然超时。
这是我的 nginx.conf 和 sites-enabled/default
/***nginx.conf***/
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 300s;
client_header_timeout 300s;
client_body_timeout 300s;
send_timeout 300s;
types_hash_max_size 2048;
}
/***sites-enabled/default***/
upstream app {
unix:[PATH]/unicorn.sock fail_timeout=120s;
}
server {
listen 80;
root [PATH];
server_name www.[URL].com [URL].com;
proxy_read_timeout 600s;
try_files $uri/index.html $uri @app;
access_log /var/log/nginx/APP_access.log combined;
error_log /var/log/nginx/APP_error.log;
location @app {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
proxy_read_timeout 600s;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 75;
}
谁能告诉我为什么 nginx 在 60 秒后仍然超时?
我可能已经通过重启服务器解决了这个问题。更改我的任何 nginx 文件后,我会 运行 service nginx reload
或 service nginx restart
但我想这实际上并没有重置我正在扩展的超时设置。
现在的问题是我不能 100% 确定我扩展的许多超时设置中的哪一个是我需要的。我可能会倒过来弄清楚这个,但我猜这是代理设置之一。
正确的解决方案仍然是(如@house9 所说)实际设置后台作业,但这是对我的问题的修复。