Server Ruby on Rails + unicorn + nginx stop responding -


my server rails worker normally, after 10 minutes without request response bad gateway. think configurations in order, don't work. don't have more ideas happening.

that configurations:

unicorn.rb:

@dir = file.expand_path(file.dirname(__file__)) + "/.."  worker_processes 2 working_directory @dir  timeout 10  listen file.join('/tmp/nutrimais.sock') listen file.join('/tmp/nutrimais_2.sock')  preload_app true# if env['rails_env'] != 'development'  gc.respond_to?(:copy_on_write_friendly=) ,   gc.copy_on_write_friendly = true  check_client_connection false  before_fork |server, worker|    signal.trap 'term'     puts 'unicorn master intercepting term , sending myself quit instead'     process.kill 'quit', process.pid   end    defined?(activerecord::base) ,     activerecord::base.connection.disconnect! end  after_fork |server, worker|    signal.trap 'term'     puts 'unicorn worker intercepting term , doing nothing. wait master send quit'   end    defined?(activerecord::base) ,     activerecord::base.establish_connection end 

nginx config:

upstream nutrimais {     # path puma sock file, defined     server unix:/tmp/nutrimais.sock max_fails=2 fail_timeout=10s;     server unix:/tmp/nutrimais_2.sock; }  server {   listen 80;   server_name dev.nutrimais.com.br;    location / {     autoindex on;     proxy_set_header x-real-ip  $remote_addr;     proxy_set_header x-forwarded-for $remote_addr;     proxy_set_header host $host;     # time out settings     proxy_next_upstream http_502 timeout;     proxy_next_upstream_timeout 0;     proxy_next_upstream_tries 0;     proxy_connect_timeout 159s;     proxy_send_timeout   600;     proxy_read_timeout   600;     proxy_buffer_size    64k;     proxy_buffers     16 32k;     proxy_busy_buffers_size 64k;     proxy_temp_file_write_size 64k;     proxy_pass_header set-cookie;     proxy_redirect     off;     proxy_hide_header  vary;     proxy_set_header   accept-encoding '';     proxy_ignore_headers cache-control expires;     proxy_set_header   referer $http_referer;     proxy_set_header   host   $host;     proxy_set_header   cookie $http_cookie;     proxy_set_header   x-real-ip  $remote_addr;     proxy_set_header x-forwarded-host $host;     proxy_set_header x-forwarded-server $host;     proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_pass http://nutrimais;   } } 

gemfile:

source 'https://rubygems.org' gem 'rails', '4.2.4' gem 'unicorn-rails', '~> 2.2' gem 'pg' gem 'mysql2', '~> 0.3.18' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'duktape' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 2.0' gem 'bootstrap-sass' gem 'devise' gem 'simple_form' gem 'minitest' gem "paperclip", "~> 4.3" gem 'aws-sdk', '< 2.0' gem 'mail_form', '~> 1.5.0.rc' gem 'sendgrid-ruby' gem 'zopim_rails' gem 'meta-tags' gem 'ckeditor' gem 'slick_rails'  group :development   gem 'better_errors'   gem 'binding_of_caller', :platforms=>[:mri_20]   gem 'quiet_assets'   gem 'rails_layout'   gem 'spring-commands-rspec'   gem 'web-console', '~> 2.0'   gem 'spring' end group :production   gem 'therubyracer' end group :development, :test   gem 'factory_girl_rails'   gem 'faker'   gem 'pry-rails'   gem 'pry-rescue'   gem 'rspec-rails'   gem 'rubocop'   gem 'byebug' end  group :test   gem 'capybara'   gem 'database_cleaner'   gem 'launchy'   gem 'selenium-webdriver' end 

log while gives bad gateway:

started "/menus" 127.0.0.1 @ 2016-01-20 17:25:17 +0000 i, [2016-01-20t17:25:17.580380 #9]  info -- : processing menuscontroller#index html d, [2016-01-20t17:25:17.904933 #9] debug -- :   [1m[36mmenu load (322.3ms)[0m  [1mselect `menus`.* `menus`  order created_at desc[0m i, [2016-01-20t17:25:20.006674 #9]  info -- : started "/menus" 127.0.0.1 @ 2016-01-20 17:25:20 +0000 

it stays in started get , not nothing

here's see going on. single unicorn backend listening on 2 sockets nginx load-balancing between them. however, 2 settings cause load balancing "stuck";

 # sets unlimited tries before trying next server     proxy_next_upstream_tries 0;   # unlimited time allowed before passing request next server  proxy_next_upstream_timeout 0; 

some recommendations:

  • try removing above lines
  • do real load balancing running second copy of backend app, or remove complexity of using upstream module , proxy_pass directly single backend app exists.

finally, when getting 502's, try testing connecting backend directly. know whether problem backend remaining down continually, or whether there issue nginx configuration.

to test app directly, can use socat connect directly socket:

$ socat - unix-connect:/you/socket/path.sock,crnl -->get / http/1.1 -->host: example.com.com -->x-forwarded-proto: https --> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -