P
P
Pianista2016-06-23 11:19:57
Nginx
Pianista, 2016-06-23 11:19:57

When deploying a rails application to a VDS. Error 110: Connection timed out. Where to dig?

On VDS, I deploy a rails application using Capistrano.
nginx + unicorn server
A few minutes after deployment, the application stops responding, the following error appears in /var/log/nginx/app_error.log:

[error] 8689#0: *64 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 94.29.117.167, server: domain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/nameapp/current/tmp/sockets/unicorn.sock:/", host: "domain.com"

After this error, the application completely stops responding. Constant error 504, after rebooting the server, everything is again in the same way.
I've looked all over and can't find a solution.
Nginx config /etc/nginx/conf.d/nameapp.conf
upstream nameapp_unicorn {
    server unix:/var/www/nameapp/current/tmp/sockets/unicorn.sock fail_timeout=0;
}

server {
    server_name domain.com;

    listen 80;

    client_max_body_size 100m;

    root       /var/www/nameapp/current/public;
    error_log  /var/log/nginx/app_error.log;
    access_log /var/log/nginx/app_access.log;

    error_page 404             /404.html;
    error_page 500 502 503 504 /50x.html;

    location /assets {
        access_log off;
        expires 30d;
    }

    location / {
        try_files $uri @app;
    }

    location @app {
        proxy_pass http://nameapp_unicorn;
        proxy_set_header Host $http_host;
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_read_timeout 150;
    }
}

Unicorn config /config/unicorn.rb
APP_PATH = File.expand_path('../../', __FILE__)

working_directory APP_PATH
listen            APP_PATH + '/tmp/sockets/unicorn.sock'
worker_processes  2
timeout           30
preload_app       true

before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = APP_PATH + '/Gemfile'
end

before_fork do |server, worker|
  ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
  Resque.redis.quit if defined?(Resque)
  sleep 1
end

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
  Resque.redis = 'localhost:6379' if defined?(Resque)
end

I will be glad for any help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pianista, 2016-09-12
@Pianista

The solution was to properly configure the runit daemon for Unicorn

A
Andrey Andreev, 2016-06-23
@b0nn1e

Make the socket path simpler in nginx and in unicorn.
For nginx:

upstream nameapp_unicorn {
    server unix:/tmp/app_name-unicorn.sock fail_timeout=0;
}

well, similarly for unicorn.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question