title: Nginx server configuration for Thin, Faye & Redis
body: <p><code>/etc/nginx/nginx.conf</code> looks like:</p>
  
  <pre><code>user  deploy;
  worker_processes  5;
  
  error_log  logs/error.log;
  
  events {
      worker_connections  1024;
      use epoll;
  }
  
  http {
  
      include       mime.types;
      default_type  application/octet-stream;
  
  
      sendfile        on;
  
      keepalive_timeout  65;
  
      upstream foreman4000 {
          server x.x.x.x:4000;
          server x.x.x.x:4001;
          server x.x.x.x:4002;
          server x.x.x.x:4003;
          server x.x.x.x:4004;
      } 
  
     server {
        listen       80;
        server_name  x.x.x.x;    #server IP
        access_log  /opt/nginx/foreman4000.access.log;
        location / {
          proxy_pass http://foreman4000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $remote_addr;
        }
     }
  }
  </code></pre>
  
  <p>Here I use gem foreman, which uses upstart to manage all process and start all servers with one command</p>
  
  <p>I created Procfile in the main directory of the project which contains:</p>
  
  <pre><code>redis:  redis-server
  thin:   bundle exec thin start -p $PORT
  faye:   rackup faye.ru -E production -s thin
  </code></pre>
  
  <p>Added to  Gemfile:</p>
  
  <pre><code>gem 'foreman'
  gem 'thin'
  gem "foreman-export-daemontools", "~&gt; 0.0.1"
  </code></pre>
  
  <p>Ran bundle install locally to edit Gemfile.lock
  Deployed project on the server.</p>
  
  <p>Started Nginx </p>
  
  <pre><code>deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx stop   [ OK ]
  deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx srart  [ OK ]
  </code></pre>
  
  <p>Exported data from Procfile to Upstart</p>
  
  <pre><code>deploy@dcards101:/var/www/cards/current$ rvmsudo foreman export upstart -a cards -u root
  </code></pre>
  
  <p>Started application</p>
  
  <pre><code>deploy@dcards101:/var/www/cards/current$ rvmsudo start cards
  </code></pre>
  
  <p>Now everything had to be good but what i see on the server is only</p>
  
  <pre><code>502 Bad Gateway
  
  nginx/1.0.15
  </code></pre>
  
  <p>Logs say:</p>
  
  <pre><code>2012/07/17 17:22:30 [error] 11593#0: *148 no live upstreams while connecting to upstream, client: x.x.x.x, server: x.x.x.x, request: "GET / HTTP/1.1", upstream: "http://foreman4000/", host: "x.x.x.x"
  </code></pre>
  
  <p>Please help with anything you can. Server -- Ubuntu 10 LTS.</p>