ruby-on-rails - Nginx 正好在 60 秒后超时

标签 ruby-on-rails ruby-on-rails-4 nginx server-sent-events

我在绑定(bind)到 unix 套接字的后端(带有 Puma 的 Rails)上有一个应用服务器
这是 nginx 配置的相关部分

location /live/ {
 proxy_pass http://app; # match the name of upstream directive which is defined above
 proxy_set_header Host $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_redirect off;
 proxy_set_header Connection 'Upgrade';
 proxy_http_version 1.1;
 chunked_transfer_encoding off;
 send_timeout 300;
 proxy_send_timeout 300;
 keepalive_timeout 7200;
}

SSE 事件来自/live/,因此我调整了 ngix 配置以处理对该路由的所有请求。

问题是连接恰好在 60 秒后关闭。这是我在响应 header 中看到的
Cache-Control:no-cache
Connection:keep-alive
Content-Type:text/event-stream
Date:Mon, 04 Nov 2013 13:41:52 GMT
Server:nginx
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:7065a7bc-3450-4fe2-b60c-33dfa8d41951
X-Runtime:0.010852
X-UA-Compatible:chrome=1
X-XSS-Protection:1; mode=block

所以似乎 nginx 将初始响应设置为关闭。为什么 keepalive_timeout 在这里不起作用。

在 nginx error.log 我看到
2013/11/04 13:42:52 [error] 3689#0: *9 upstream timed out (110: Connection timed out)   while reading upstream, client: ......., server: myapp.com, request: "GET /live/events HTTP/1.1", upstream: "http://unix:/home/ubuntu/myapp/shared/sockets/puma.sock:/live/events", host: "myapp.com"

最佳答案

以防万一其他人在使用 Nginx + Puma + Rails 时遇到超时错误,Nginx 中的以下配置应将超时增加到 605 秒(10 分 5 秒):

server {
    # ... here goes your proxy configuration

    # Avoid 504 HTTP Timeout Errors
    proxy_connect_timeout       605;
    proxy_send_timeout          605;
    proxy_read_timeout          605;
    send_timeout                605;
    keepalive_timeout           605;
}

关于ruby-on-rails - Nginx 正好在 60 秒后超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19769072/

相关文章:

css - Bootstrap 导航栏居中链接并右对齐其他链接

Nginx:重定向除一个之外的所有

ruby-on-rails - capybara 及之前(:all) in rspec

ruby-on-rails - Rails 选择字段助手的 block 未按预期工作

ruby-on-rails - Capistrano throw 装置 secret_key 未设置

php - 在 Alpine 上运行 nginx

nginx - 如何让 nginx 添加标题而不将其转换为小写?

ruby-on-rails - 在 rails 控制台中选择第二个条目?

javascript - Rails Controller 中的 Ajax 功能实现

ruby-on-rails - 无法让 mongoid 与 Rails 4 一起工作