ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

ruby-on-rails – Nginx在60秒后完全超时

2019-08-23 06:09:52  阅读:147  来源: 互联网

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


我在后端(与Puma的Rails)绑定到unix套接字的app服务器
这是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秒后完全关闭.这是我在响应头中看到的内容

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将初始响应设置为close.为什么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的Timeout错误,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;
}

标签:server-sent-events,ruby-on-rails,nginx,ruby-on-rails-4
来源: https://codeday.me/bug/20190823/1695818.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有