0

/etc/nginx/nginx.conf looks like:

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;
      }
   }
}

Here I use gem foreman, which uses upstart to manage all process and start all servers with one command

I created Procfile in the main directory of the project which contains:

redis:  redis-server
thin:   bundle exec thin start -p $PORT
faye:   rackup faye.ru -E production -s thin

Added to Gemfile:

gem 'foreman'
gem 'thin'
gem "foreman-export-daemontools", "~> 0.0.1"

Ran bundle install locally to edit Gemfile.lock Deployed project on the server.

Started Nginx

deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx stop   [ OK ]
deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx srart  [ OK ]

Exported data from Procfile to Upstart

deploy@dcards101:/var/www/cards/current$ rvmsudo foreman export upstart -a cards -u root

Started application

deploy@dcards101:/var/www/cards/current$ rvmsudo start cards

Now everything had to be good but what i see on the server is only

502 Bad Gateway

nginx/1.0.15

Logs say:

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"

Please help with anything you can. Server -- Ubuntu 10 LTS.

Ostap Tan
  • 111
  • 3
  • 13

2 Answers2

0

got the same error solved it this way:

first install nginx_tcp_proxy_module

( I followed this tutorial but changed it to use passenger and thin with nginx)

than add the tcp part to your nginx.conf:

tcp {
    upstream websockets {
        ## node processes
        server 12.34.56.78:9292; 
        check interval=300 rise=2 fall=5 timeout=1000;
    }   

    server {
        listen 9200;
        server_name domain.org;
        tcp_nodelay on;
        proxy_pass websockets;
    }
}

doesn´t work on port 80 for me

after that I still get empty responses from faye/privat_pub but there was an extremly trivial solution:

RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production

look private_pub - Issue #29

Now everything works except chrome how fires 2 times

(and I need an deamon-process for the rackup)

hope it helps you too

twetzel
  • 99
  • 1
  • 6
  • Thank you very much but it's not exactly what I need. I guess that my fault is somewhere in upstream, in rails server. But I can't find what is the problem. If I can start Thin well I guess everything should be OK. – Ostap Tan Jul 24 '12 at 10:05
0

I think your problem is that you put your app-server and the faye server in the same upstream!

If I get the method of upstream and foreman right, your first visitor get the app the second faye and so on. ( maybe I`m wrong because I don´t know foreman .. but if foreman shares all available servers to all services, that might be your problem )

I wood say try capistrano instead of foreman .. so you have full control which server starts where .. because at my my host http don`t work for private_pub (because of nginx) so I had to install the nginx_tcp_proxy_module to get the tcp block working in my nginx.conf

or just try server by server via ssh to find the error

twetzel
  • 99
  • 1
  • 6