title: Need help with monit alerts on connection of Nginx
body: <p>I hope somewhere out there will be able to help me on this. I have my production evironment as follows:</p>
  
  <pre><code>Rails 2.3.5
  Passenger 2.2.11
  Nginx
  Monit
  </code></pre>
  
  <p>It seems that everything is working as it's supposed to be but, 2 or 3 times a day, I get an email from Monit as follows:</p>
  
  <pre><code>monit alert -- Connection failed nginx
  
  To: myemail@domain.com
  Connection failed Service nginx
  
      Date:        Thu, 11 Nov 2010 10:46:44 +0000
      Action:      restart
      Host:        mydomain
      Description: 'nginx' failed, cannot open a connection to INET[mydomain.com:80] via TCP
  
  Your faithful employee,
  monit
  </code></pre>
  
  <p>Then after about 30 seconds, I have another email as follows:</p>
  
  <pre><code>Connection passed Service nginx
  
      Date:        Thu, 11 Nov 2010 10:47:16 +0000
      Action:      alert
      Host:        mydomain
      Description: 'nginx' connection passed to INET[mydomain.com:80] via TCP
  
  Your faithful employee,
  monit
  </code></pre>
  
  <p>In my monit config file I have the followings:</p>
  
  <pre><code>set daemon 30
  check process nginx with pidfile /opt/nginx/logs/nginx.pid
    start program = "/opt/nginx/sbin/nginx"
    stop program = "/opt/nginx/sbin/nginx -s stop"
    if failed host mydomain.com port 80 protocol http request / then restart
    if 5 restarts within 5 cycles then timeout
  </code></pre>
  
  <p>And in Nginx log around that time, I have this:</p>
  
  <pre><code>2010/11/11 10:46:44 [notice] 3812#0: signal process started
  *** Exception Errno::EPIPE in Passenger RequestHandler (Broken pipe) (process 3803):
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/rack/request_handler.rb:94:in `write'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/rack/request_handler.rb:94:in `process_request'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/utils.rb:184:in `safe_fork'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:163:in `start'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `__send__'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
      from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/gems/1.8/gems/passenger-2.2.11/bin/passenger-spawn-server:61
  </code></pre>
  
  <p>I couldn't make out what's causing this problem. I have tried putting the max_pool_size to 30 in Passenger config file and it didn't make any difference yet.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks.</p>