504网关超时错误 - 我的rails站点将无法运行

时间:2014-01-21 05:48:21

标签: ruby-on-rails-3 nginx capistrano unicorn digital-ocean

我已使用rails applicationdigitalocean设置为部署在capistrano小滴上。然而,出于某种奇怪的原因,无论我做什么,我都会得到504 Gateway Timeout nginx error。我尝试重新启动独角兽,但错误仍然存​​在。

我在这里列出了unicorn.log文件的最后50行 - 这里可能出现什么问题?

/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/open-uri.rb:29:in `initialize'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/open-uri.rb:29:in `open'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/open-uri.rb:29:in `open'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/open-uri.rb:29:in `open'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/logger.rb:592:in `open_logfile'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/logger.rb:549:in `initialize'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/logger.rb:314:in `new'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/logger.rb:314:in `initialize'
/home/etyme/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/logger.rb:72:in `initialize'
/home/etyme/releases/20140120142015/config/environments/development.rb:53:in `new'
/home/etyme/releases/20140120142015/config/environments/development.rb:53:in `block in <top (required)>'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:24:in `class_eval'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:24:in `configure'
/home/etyme/releases/20140120142015/config/environments/development.rb:1:in `<top (required)>'
/home/etyme/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/home/etyme/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/home/etyme/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/etyme/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:571:in `block in <class:Engine>'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/home/etyme/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/etyme/releases/20140120142015/config/environment.rb:5:in `<top (required)>'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
config.ru:4:in `block in <main>'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `eval'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `block in builder'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `call'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `build_app!'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:595:in `init_worker_process'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:615:in `worker_loop'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:511:in `maintain_worker_count'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:277:in `join'
/usr/bin/unicorn:121:in `<main>'
E, [2014-01-21T05:42:51.210093 #30994] ERROR -- : reaped #<Process::Status: pid 31079 exit 1> worker=0
I, [2014-01-21T05:42:51.210263 #30994]  INFO -- : worker=0 spawning...
I, [2014-01-21T05:42:51.213421 #31093]  INFO -- : worker=0 spawned pid=31093
I, [2014-01-21T05:42:51.228866 #31093]  INFO -- : Refreshing Gem list
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/bundler-1.5.1/lib/bundler/runtime.rb:220: warning: Insecure world writable dir /home/etyme/releases in PATH, mode 040777
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/bundler-1.5.1/lib/bundler/runtime.rb:220: warning: Insecure world writable dir /home/etyme/releases in PATH, mode 040777

这是我的nginx conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;
        gzip_disable "msie6";
        gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

1 个答案:

答案 0 :(得分:1)

您正在打开与另一个超时的网站的HTTP连接。由于该网站没有失败,但等待从您应用内的代码正确连接,您的应用请求永远不会完成,现在请求您的应用超时。

您可以采取以下措施来解决此问题:

  • 修复您的配置。也许你在这个连接上有错误的主机/端口?你在错误的地方,它只是悬挂而不是失败
  • 在此连接上设置10-20秒的正确HTTP超时。超时时优雅失败。
  • 完全删除此代码,因为您尝试使用的资源似乎不稳定