ruby-on-rails – Nginx,Rails和Oauth.上游过早关闭连接

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Nginx,Rails和Oauth.上游过早关闭连接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个奇怪的问题出现在生产环境中,只有当我使用Nginx和独角兽.当我使用没有Nginx的独角兽,它不会发生.

问题.我有一个简单的oauth身份验证,允许用户通过GitHub注册.在GitHub的授权页面上按“允许”后,用户重定向到回呼路由.然后他/她获得302坏网关错误.
Nginx日志显示我这个错误(键被替换为“…”)

2012/12/26 18:03:08 [error] 1467#0: *1 upstream prematurely closed
connection while reading response header from upstream,client:
10.0.2.2,server: _,request: “GET /auth/github/callback?code=&state=…
HTTP/1.1”,upstream:
“http://unix:/tmp/unicorn.tm.sock:/auth/github/callback?code=…&state=…”,
host: “localhost:3000”

Ther是我的Nginx配置.

upstream unicorn {
  server unix:/tmp/unicorn.tm.sock fail_timeout=0;
}

server {
  listen 80 default deferred;

  client_max_body_size 4G;
  server_name _;

  keepalive_timeout 75s;

  proxy_connect_timeout 60s;
  proxy_read_timeout 60s;


  root /vagrant/public;

  try_files $uri/index.html $uri.html $uri @app;

  location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;

    proxy_redirect off;

    proxy_pass http://unicorn;

    proxy_buffer_size 16k;
    proxy_busy_buffers_size 16k;
  }

  error_page 500 502 503 504 /500.html;
}

所以我的问题是为什么会发生这种情况,有没有可能的修复?

我一直在搜索一段时间,但没有运气.

更新

感谢您的评论,我刚刚尝试设置fail_timeout = 30s,它有帮助,但是请求大约需要40秒才能完成.但是不管怎么说,我会尝试使用这个参数来过期.

我更新了我的配置,根据建议,但仍然,得到相同的错误.

另外,这是独角兽错误日志.似乎它杀死了需要超过30秒的请求,但我猜从oauth站点重定向不可能那么长

(github) Request phase initiated.
(github) Callback phase initiated.
E,[2012-12-26T19:33:13.058183 #6002] ERROR -- : worker=0 PID:6005 timeout (31s > 30s),killing
E,[2012-12-26T19:33:13.067011 #6002] ERROR -- : reaped #<Process::Status: pid 6005 SIGKILL (signal 9)> worker=0
I,[2012-12-26T19:33:13.067198 #6002]  INFO -- : worker=0 spawning...
I,[2012-12-26T19:33:13.068631 #6012]  INFO -- : worker=0 spawned pid=6012
I,[2012-12-26T19:33:13.068726 #6012]  INFO -- : Refreshing Gem list
I,[2012-12-26T19:33:17.140948 #6012]  INFO -- : worker=0 ready

独角兽配置

rails_env = ENV['RAILS_ENV'] || 'production'

worker_processes 1

listen "/tmp/unicorn.tm.sock",:backlog => 64
listen 8080,:tcp_nopush => true

timeout 30

pid "/tmp/unicorn.pid"

stderr_path "/tmp/unicorn.log"
stdout_path "/tmp/unicorn.log"

check_client_connection false

解决方法

ERROR -- : worker=0 PID:6005 timeout (31s > 30s),killing

不用说,你只需要安装超时到你的unicorn配置的30多个

至少尝试一下

timeout 60

http://unicorn.bogomips.org/Unicorn/Configurator.html#method-i-timeout

原文链接:https://www.f2er.com/ruby/273350.html

猜你在找的Ruby相关文章