unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Nginx Socket with Multiple Unicorn instances
@ 2010-04-05 20:05 William N Prater III
  2010-04-05 20:34 ` Iñaki Baz Castillo
  2010-04-05 23:29 ` Eric Wong
  0 siblings, 2 replies; 4+ messages in thread
From: William N Prater III @ 2010-04-05 20:05 UTC (permalink / raw)
  To: mongrel-unicorn

Hello,

Is it possible to run one Nginx socket that is used by multiple master Unicorn processes for different applications?  Or does one need to setup a new upstream for each?

TIA


_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nginx Socket with Multiple Unicorn instances
  2010-04-05 20:05 Nginx Socket with Multiple Unicorn instances William N Prater III
@ 2010-04-05 20:34 ` Iñaki Baz Castillo
  2010-04-05 20:40   ` William N Prater III
  2010-04-05 23:29 ` Eric Wong
  1 sibling, 1 reply; 4+ messages in thread
From: Iñaki Baz Castillo @ 2010-04-05 20:34 UTC (permalink / raw)
  To: unicorn list

2010/4/5 William N Prater III <will@thesuperformula.com>:
> Hello,
>
> Is it possible to run one Nginx socket that is used by multiple master Unicorn processes for different applications?  Or does one need to setup a new upstream for each?

Do you mean different Unicorn servers listening into the same socket?
it doesn't make sense IMHO.


-- 
Iñaki Baz Castillo
<ibc@aliax.net>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nginx Socket with Multiple Unicorn instances
  2010-04-05 20:34 ` Iñaki Baz Castillo
@ 2010-04-05 20:40   ` William N Prater III
  0 siblings, 0 replies; 4+ messages in thread
From: William N Prater III @ 2010-04-05 20:40 UTC (permalink / raw)
  To: unicorn list

On Apr 5, 2010, at 1:34 PM, Iñaki Baz Castillo wrote:

> 2010/4/5 William N Prater III <will@thesuperformula.com>:
>> Hello,
>> 
>> Is it possible to run one Nginx socket that is used by multiple master Unicorn processes for different applications?  Or does one need to setup a new upstream for each?
> 
> Do you mean different Unicorn servers listening into the same socket?
> it doesn't make sense IMHO.

It may not make any sense.  Im not sure how Nginx handles the vhost and proxies.  I was hoping to find an easier way to deploy new apps.  Otherwise I have to edit a few config file each time. 

_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Nginx Socket with Multiple Unicorn instances
  2010-04-05 20:05 Nginx Socket with Multiple Unicorn instances William N Prater III
  2010-04-05 20:34 ` Iñaki Baz Castillo
@ 2010-04-05 23:29 ` Eric Wong
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Wong @ 2010-04-05 23:29 UTC (permalink / raw)
  To: unicorn list

William N Prater III <will@thesuperformula.com> wrote:
> Hello,
> 
> Is it possible to run one Nginx socket that is used by multiple master
> Unicorn processes for different applications?  Or does one need to
> setup a new upstream for each?

Hi William,

Nginx socket?  It's ambiguous what you mean by that, but since you
mention upstreams I'll assume you mean UNIX domain sockets bound by
Unicorn that nginx connects to.

Generally, you'll have to create a new upstream for each, but nginx can
listen on the same HTTP socket (usually port 80) and use virtual hosts.

So I assume you'll do something like this to talk to separate Unicorn
masters:

  upstream unicorn_a {
    server unix:/tmp/.a fail_timeout=0;
  }
  upstream unicorn_b {
    server unix:/tmp/.b fail_timeout=0;
  }
  server {
    # catch all, this serves an error to people that connect w/o a host name
    listen 80 default deferred;
    server_name _;
    root /srv/default;
  }
  server {
    server_name a.example.com;
    root /srv/a;
    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      if (!-f $request_filename) {
        proxy_pass http://unicorn_a;
      }
    }
  }
  server {
    server_name b.example.com;
    root /srv/b;
    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      if (!-f $request_filename) {
        proxy_pass http://unicorn_b;
      }
    }
  }

However, if you _really_ trust your apps and frameworks to work
correctly in the same process, you can run multiple apps within the same
Rack server, you can actually have virtual hosts this way in Rack:

--------------------------- 8< ----------------------------
use Rack::ContentLength
use Rack::ContentType, 'text/plain'
# more global middlewares can go here

# virtual hosts:
map "http://a.example.com/" do
  run lambda { |env| [ 200, {}, [ "Hello A\n" ] ] }
end
map "http://b.example.com/" do
  run lambda { |env| [ 200, {}, [ "Hello B\n" ] ] }
end
--------------------------- 8< ----------------------------

However, if your apps (or dependent libraries/frameworks) share any
global resources in an unintended or unsafe manner, then you won't be
able to do this.  The above example is of course highly trivial.

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-05 23:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-05 20:05 Nginx Socket with Multiple Unicorn instances William N Prater III
2010-04-05 20:34 ` Iñaki Baz Castillo
2010-04-05 20:40   ` William N Prater III
2010-04-05 23:29 ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).