title: 504 Gateway Time-out nginx/1.4.6 (Ubuntu)
body: <p>Follow rails one app click deployment. Database done well, even I check rails console everything working fine.</p>
  
  <p>Ruby version is 2.3.0 and rails version is 5.0.1</p>
  
  <p>But when I hit IP address it gives an error time out</p>
  
  <p>on check unicorn logs I get </p>
  
  <pre><code>/usr/local/rvm/gems/ruby-2.2.1/gems/unicorn-5.0.1/bin/unicorn:126:in `&lt;top (required)&gt;'
  /usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `load'
  /usr/local/rvm/gems/ruby-2.2.1/bin/unicorn:23:in `&lt;main&gt;'
  /usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `eval'
  /usr/local/rvm/gems/ruby-2.2.1@global/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  E, [2017-02-26T15:47:18.969274 #9861] ERROR -- : reaped #&lt;Process::Status: pid 11928 exit 1&gt; worker=2
  I, [2017-02-26T15:47:18.969471 #9861]  INFO -- : worker=2 spawning...
  I, [2017-02-26T15:47:18.974112 #11942]  INFO -- : worker=2 spawned pid=11942
  I, [2017-02-26T15:47:18.978540 #11936]  INFO -- : Refreshing Gem list
  I, [2017-02-26T15:47:18.986558 #11938]  INFO -- : Refreshing Gem list
  </code></pre>
  
  <p>and nginx error is</p>
  
  <pre><code>017/02/26 15:34:17 [error] 18564#0: *31 connect() to unix:/var/run/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 121.52.156.57, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock:/", host: "188.166.157.124"
  2017/02/26 15:35:42 [error] 32360#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.155.34.115, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
  2017/02/26 15:42:38 [error] 6296#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 119.152.140.90, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "188.166.157.124"
  </code></pre>
  
  <p>unicorn.conf</p>
  
  <pre><code>listen "unix:/var/run/unicorn.sock"
  worker_processes 4
  user "rails"
  working_directory "/home/rails/company_startup"
  pid "/var/run/unicorn.pid"
  stderr_path "/var/log/unicorn/unicorn.log"
  stdout_path "/var/log/unicorn/unicorn.log"
  </code></pre>
  
  <p>ps aux | grep unicor</p>
  
  <pre><code>rails     4751 18.0  4.2 172880 21516 ?        R    14:59   0:00 unicorn worker[2] -D -c /etc/unicorn.conf -E production                                                                                              
  rails     4757  0.0  4.1 172404 20972 ?        Rl   14:59   0:00 unicorn worker[3] -D -c /etc/unicorn.conf -E production                                                                                              
  rails     4760  0.0  2.9 159860 14568 ?        Rl   14:59   0:00 unicorn worker[1] -D -c /etc/unicorn.conf -E production                                                                                              
  root      4764  0.0  0.1  11712   620 pts/0    S+   14:59   0:00 grep --color=auto unicorn
  root     20463  0.4  2.6 146740 13176 ?        Sl   04:32   2:48 unicorn master -D -c /etc/unicorn.conf -E production
  </code></pre>
  
  <p>nginx file here: </p>
  
  <pre><code>upstream app_server {
  server unix:/var/run/unicorn.sock fail_timeout=0;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>server {
  listen   80;
  root /home/rails/company_startup/public;
  server_name _;
  index index.htm index.html;
  client_max_body_size 1M;
  location / {
          try_files $uri/index.html $uri.html $uri @app;
  }
  
  location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
                  try_files $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://app_server;
  }
  }
  </code></pre>