Search code examples
ruby-on-railsruby-on-rails-4nginxunicorndigital-ocean

Nginx Unicorn Rails - 504 Gateway Time-out


I am using the Ruby on Rails One-Click Application on DigitalOcean After setting up everything i am getting the following error

    2016/06/10 07:48:28 [error] 1702#0: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 106.51.23.165, server: 107.170.3.237, request
: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "107.170.3.237"
2016/06/10 07:49:45 [error] 1702#0: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 106.51.23.165, server: 107.170.3.237, request
: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "107.170.3.237"
2016/06/10 07:54:14 [error] 2954#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.171.105.237, server: 107.170.3.237, reque
st: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "107.170.3.237"
2016/06/10 07:58:54 [error] 3278#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 122.171.105.237, server: 107.170.3.237, reque
st: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock/", host: "107.170.3.237"

/etc/unicorn.conf

listen "unix:/var/run/unicorn.sock"
#listen "/tmp/unicorn.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/skreem-ror"
pid "/var/run/unicorn.pid"
stderr_path "/var/log/unicorn/unicorn.log"
stdout_path "/var/log/unicorn/unicorn.log"

/etc/default/unicorn

# Change paramentres below to appropriate values and set CONFIGURED to yes.
CONFIGURED=yes

# Default timeout until child process is killed during server upgrade,
# it has *no* relation to option "timeout" in server's config.rb.
TIMEOUT=60

# Path to your web application, sh'ld be also set in server's config.rb,
# option "working_directory". Rack's config.ru is located here.
APP_ROOT=/home/rails/skreem-ror

# Server's config.rb, it's not a rack's config.ru
CONFIG_RB=/etc/unicorn.conf

# Where to store PID, sh'ld be also set in server's config.rb, option "pid".
PID=/var/run/unicorn.pid
RAILS_ENV="development"
UNICORN_OPTS="-D -c $CONFIG_RB -E $RAILS_ENV"

PATH=/usr/local/rvm/rubies/ruby-2.3.1/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-2.3.1@global/bin:/usr/local/rvm/gems/ruby-2.3.1/bin/
export GEM_HOME=/usr/local/rvm/gems/ruby-2.3.1
export GEM_PATH=/usr/local/rvm/gems/ruby-2.3.1:/usr/local/rvm/gems/ruby-2.3.1@global
DAEMON=/usr/local/rvm/gems/ruby-2.3.1/bin/unicorn

/etc/nginx/sites-enabled/rails

upstream app_server {
    server unix:/var/run/unicorn.sock fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/skreem-ror/public;
    server_name 107.170.3.237 skreem.in www.skreem.in admin.skreem.in brands.skreem.in api.skreem.in;
    index index.htm index.html;

    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;
    }
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 50M;
    proxy_read_timeout 300;
}

Solution

  • It looks like you need to add gem unicorn to your Gemfile and run bundle install.