我有一个奇怪的问题,只有在我使用nginx和unicorn时才出现在生产环境中。当我使用没有nginx的独角兽时,它不会发生。
问题所在。我有一个简单的oauth身份验证,允许用户通过GitHub注册。在GitHub的授权页面上按“允许”后,用户将被重定向到回叫路由。然后,他/她得到302 Bad Gateway
错误。
Nginx日志显示我的错误(键被“......”替换)
2012/12/26 18:03:08 [错误] 1467#0:* 1上游过早关闭 从上游,客户端读取响应头时连接: 10.0.2.2,server:_,request:“GET / auth / github / callback?code =& state = ... 上游:HTTP / 1.1“ “HTTP:// UNIX:/tmp/unicorn.tm.sock:?/认证/ github上/回调代码= ...&放大器;状态= ...” 主持人:“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
unicorn config
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
答案 0 :(得分:24)
ERROR -- : worker=0 PID:6005 timeout (31s > 30s), killing
不用说,你只需要在unicorn config中设置超时超过30
至少尝试
timeout 60
http://unicorn.bogomips.org/Unicorn/Configurator.html#method-i-timeout