pjveadev
By:
pjveadev

504 Gateway Time-out NGINX + Unicorn Ubuntu 14 Ruby on Rails

June 16, 2014 13.8k views
I recently deployed a new version of my Ruby on Rails application (veasoftware). I added active_admin support so I had to run "bundle install". This required me to install git. After completing these steps I am getting a "504 Gateway Time-out" error. I tried running unicorn in development mode and everything works. But in production it does not. NGINX Error.log
    2014/06/16 17:17:56 [error] 17282#0: *153 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 123.125.71.46, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "tutorials.veasoftware.com"
2014/06/16 17:23:12 [error] 17282#0: *162 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 185.5.153.114, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "www.veasoftware.com"
2014/06/16 17:37:44 [error] 17282#0: *172 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 189.177.5.146, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "www.veasoftware.com"
2014/06/16 17:37:47 [error] 17282#0: *175 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 67.22.168.113, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "veasoftware.com", referrer: "http://www.google.com/url?sa=D&q=http://veasoftware.com/&usg=AFQjCNHVnRaJX4JHeEnScPmw_naIwCMFyw"
2014/06/16 17:40:07 [error] 17282#0: *180 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 180.76.5.149, server: _, request: "GET /2013/10/10/how-to-add-iads/ HTTP/1.1", upstream: "http://127.0.0.1:8080/2013/10/10/how-to-add-iads/", host: "www.veasoftware.com"
unicorn.log
    E, [2013-12-20T02:08:44.787584 #4461] ERROR -- : reaped # worker=1
I, [2013-12-20T02:08:44.787734 #4461]  INFO -- : worker=1 spawning...
/home/rails/config/boot.rb:4:in `require': no such file to load -- bundler/setup (LoadError)
    from /home/rails/config/boot.rb:4
    from /home/rails/config/application.rb:1:in `require'
    from /home/rails/config/application.rb:1
    from /home/rails/config/environment.rb:2:in `require'
    from /home/rails/config/environment.rb:2
    from config.ru:4:in `require'
    from config.ru:4
    from /usr/lib/ruby/vendor_ruby/rack/builder.rb:51:in `instance_eval'
    from /usr/lib/ruby/vendor_ruby/rack/builder.rb:51:in `initialize'
    from config.ru:1:in `new'
    from config.ru:1
E, [2013-12-20T02:08:44.790693 #4461] ERROR -- : reaped # worker=0
I, [2013-12-20T02:08:44.790899 #4461]  INFO -- : worker=0 spawning...
I, [2013-12-20T02:08:44.791952 #6246]  INFO -- : worker=1 spawned pid=6246
/home/rails/config/boot.rb:4:in `require': no such file to load -- bundler/setup
Does anyone have any suggestions?
4 Answers
Looks like you forgot to bundle install?
Any breakthroughs on this? I'm running into the same issue.
  • I'm think that this has something to do with the gems not being accessible to the "rails" user. I had some success by editing /home/unicorn/unicorn.conf and commenting out the line
    user "rails"
    then restarting unicorn:
    service unicorn restart
    

I'm also hitting this problem. One thing is Bundler did warn me about running "bundle install" and "bundle update" from root as it would break everything...

commenting out user "rails" also worked for me but a detailed look at the running processes shows that unicorn is now running as root, which I think is not particularly secure.

This looks like a similar issue to: https://www.digitalocean.com/community/questions/getting-time-out-error-when-trying-to-deploy-rails-4-app-on-nginx

Not sure if this will help in your case, but here's what happened to me:

When I used the one-click Rails creation, it defaulted to Ruby 2.0.0. I used RVM commands to change this to 1.9.3. Based on my Gemfile, bundler wouldn't let me run bundle install until I did so.

I tried changing it back to 2.0.0 as the default, re-running bundle install (and the whole kit and kabootle of "bundle exec rake db:migrate", "bundle exec rake assets:precompile"), and restarting the Unicorn service ("service unicorn restart"), the 504 error was gone!

I don't have anything really holding me back to 1.9.3, so for me, I can just update my development environment to match. I'm not sure what the solution would be otherwise.. perhaps building the RoR environment from scratch on a fresh Ubuntu droplet, vs using the one-click option?

Let me know if this fits the bill for you!

Have another answer? Share your knowledge.