Question

Nginx + Ruby On Rails = 504 Gateway Time-out

  • Posted August 28, 2014

Hi there!

5th droplet attempt at DigitalOcean. I’ve followed all the steps provided by DigitalOcean guides (one click image etc…). I’ve uploaded my site by FTP, run bundle install, run rake db:migrate, I’ve even connected to my DB remotely and populated it with an old backup. Everything is perfect.

Except one thing. I haven’t been able to run my site not once. I get the classic “504 Gateway Time-out” error many have posted here although none has a response yet.

What is going on?

A few notes…

When running bundle install:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.

nginx/error.log

2014/08/28 21:47:32 [error] 16805#0: *32 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 190.18.93.156, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "objectservers.com.ar"

log/unicorn.log

/usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler.rb:302: warning: Insecure world writable dir /home/rails in PATH, mode 040777
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler.rb:302: warning: Insecure world writable dir /home/rails in PATH, mode 040777
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/runtime.rb:34:in `block in setup': You have already activated rack 1.6.0.beta, but your Gemfile requires rack 1.5.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/runtime.rb:19:in `setup'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler.rb:121:in `setup'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/setup.rb:17:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
	from /home/rails/config/boot.rb:4:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/rails/config/application.rb:1:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/rails/config/environment.rb:2:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from config.ru:4:in `block in <main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.0.beta/lib/rack/builder.rb:55:in `instance_eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.0.beta/lib/rack/builder.rb:55:in `initialize'
	from config.ru:1:in `new'
	from config.ru:1:in `<main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `block in builder'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `call'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `build_app!'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:623:in `init_worker_process'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:643:in `worker_loop'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:527:in `spawn_missing_workers'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:538:in `maintain_worker_count'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:303:in `join'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/bin/unicorn:126:in `<top (required)>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `load'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `<main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/runtime.rb:34:in `block in setup': You have already activated rack 1.6.0.beta, but your Gemfile requires rack 1.5.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/runtime.rb:19:in `setup'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler.rb:121:in `setup'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.2/lib/bundler/setup.rb:17:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
	from /home/rails/config/boot.rb:4:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/rails/config/application.rb:1:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /home/rails/config/environment.rb:2:in `<top (required)>'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from config.ru:4:in `block in <main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.0.beta/lib/rack/builder.rb:55:in `instance_eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/rack-1.6.0.beta/lib/rack/builder.rb:55:in `initialize'
	from config.ru:1:in `new'
	from config.ru:1:in `<main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `block in builder'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `call'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `build_app!'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:623:in `init_worker_process'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:643:in `worker_loop'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:527:in `spawn_missing_workers'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:538:in `maintain_worker_count'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:303:in `join'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/unicorn-4.7.0/bin/unicorn:126:in `<top (required)>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `load'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/unicorn:23:in `<main>'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
	from /usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
E, [2014-08-28T21:52:49.144863 #32524] ERROR -- : reaped #<Process::Status: pid 4237 exit 1> worker=1
I, [2014-08-28T21:52:49.145159 #32524]  INFO -- : worker=1 spawning...
E, [2014-08-28T21:52:49.145979 #32524] ERROR -- : reaped #<Process::Status: pid 4234 exit 1> worker=0
I, [2014-08-28T21:52:49.146203 #32524]  INFO -- : worker=0 spawning...
I, [2014-08-28T21:52:49.147495 #4240]  INFO -- : worker=1 spawned pid=4240
I, [2014-08-28T21:52:49.147709 #4240]  INFO -- : Refreshing Gem list
I, [2014-08-28T21:52:49.151910 #4242]  INFO -- : worker=0 spawned pid=4242
I, [2014-08-28T21:52:49.152180 #4242]  INFO -- : Refreshing Gem list

I would really appreciate any help. It’s been days I’ve been meaning to finally try out DigitalOcean.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

  1. Running Bundler as root. It says don’t do that, so don’t do that. Create a non-root user and run Bundler as that user.
  2. Probably caused by #3.
  3. warning: Insecure world writable dir /home/rails in PATH, mode 040777 - you should really fix that, but it’s not the problem.

The useful information in stack traces is usually in the first line or so. In this case, it’s this:

You have already activated rack 1.6.0.beta, but your Gemfile requires rack 1.5.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

It even gives you the solution to the problem. Put bundle exec before the command you use to start your application. See if it works better.

Just wanted to chime in that following Digital Ocean’s tutorial (https://www.digitalocean.com/community/tutorials/how-to-use-the-ruby-on-rails-one-click-application-on-digitalocean#configuration-details), I get this exact same problem. Trying to run ‘bundle install’ as root gets you the warning from Bundler that you shouldn’t do that, but trying to run it as rails user gets you the error that you do not have permission to install gems. Awesome! I chose to run it as root, and now have the Rack version problem with Unicorn. Will try some of these solutions and see if I can get my app running.

This comment has been deleted