Answer the question
In order to leave comments, you need to log in
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"
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;
}
}
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
Answer the question
In order to leave comments, you need to log in
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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question