title: What does this nginx + Ruby on Rails error mean: connect() failed (111: Connection refused) while reading response header from upstream
body: <p>I've just recently taken over a Ruby on Rails project that uses a staging app and a production app. Unfortunately the person who set this up is MIA. I ran the "deploy" script (Capistrano) to deploy to the staging server, but it brought the house down </p>
  
  <p>In the nginx logs I see this: connect() failed (111: Connection refused) while reading response header from upstream</p>
  
  <p>Not familiar with nginx. Can someone tell me what this means?</p>
  
  <p>nginx.conf</p>
  
  <pre><code>##################
  # STAGING SETTINGS
      upstream staging_mongrel {
          server 127.0.0.1:8003;
          }
  
      server {
          listen       80;
          server_name  staging.removed.org;
          root /var/www/apps/staging/current/public;
  
          index  index.html index.htm;
          location / {
              proxy_set_header  X-Real-IP  $remote_addr;
              proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_redirect false;
  
              proxy_connect_timeout     90;
              proxy_send_timeout       400;
              proxy_read_timeout      3600;
  
              client_max_body_size     20m;
  
              if (-f $request_filename/index.html) {
                   rewrite (.*) $1/index.html break;
              }
              if (-f $request_filename.html) {
                  rewrite (.*) $1.html break;
              }
              if (!-f $request_filename) {
                  proxy_pass http://staging_mongrel;
                  break;
              }
           }
           error_page   500 502 503 504  /50x.html;
           location = /50x.html {
               root   html;
           }
      }
  }
  </code></pre>