# Multiple apps on one lighty server

**URL:** <https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195>\
**Category:** Deployment\
**Created:** [August 16, 2007, 7:10am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195 "2007-08-16T07:10:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 16, 2007, 7:10am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/1 "2007-08-16T07:10:33Z")

</div>

Does anybody know how to run multiple rails apps off of one server?  
All I can imagine is running mongrel with different port numbers, but  
since (internal server) lighttpd is set up to run on port 81, and  
mongrel is a layer below lighty, that would mean that the machine would  
be serving at 192.168.0.119::81:3000 for example. And I don’t think that  
multiple ports are allowed, so that doesn’t work. Anybody know how to do  
it? Birds-eye view is fine. Once I understand that, I can probably look  
up the specifics on the net.

Thanks!

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 16, 2007, 10:45am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/2 "2007-08-16T10:45:33Z")

</div>

Hi Sean

> since (internal server) lighttpd is set up to run on port 81, and  
> mongrel is a layer below lighty, that would mean that the machine would  
> be serving at 192.168.0.119::81:3000 for example. And I don’t think that  
> multiple ports are allowed, so that doesn’t work. Anybody know how to do

Ports in Unix are not in any way hierarchical. So, you would have  
lighty listening on port 81;

192.168.0.119:81

…and mongrel(s) listening on port(s) 3000 (and up), i.e;

192.168.0.119:3000

…and maybe

192.168.0.119:3001  
192.168.0.119:3002  
…

…depending on your setup

So, the idea is that a request comes in on port 81, and lighty  
redirects it to a different port (3000, or whatever).

Cheers

David

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 16, 2007, 11:14am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/3 "2007-08-16T11:14:32Z")

</div>

Thanks David. But I’m still confused. Would the browser looking for one  
of the apps be pointing to 192.168.0.119:81 or 192.168.0.119:3000? I’d  
guess it’d have to be 192.168.0.119:3000, because otherwise lighty has  
no way to know who to redirect to, but if it it is 3000, then how does  
the server know to give the request to lighty in the first place?

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 16, 2007, 11:44am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/4 "2007-08-16T11:44:40Z")

</div>

Sean C. wrote:

> Thanks David. But I’m still confused. Would the browser looking for one  
> of the apps be pointing to 192.168.0.119:81 or 192.168.0.119:3000? I’d  
> guess it’d have to be 192.168.0.119:3000, because otherwise lighty has  
> no way to know who to redirect to, but if it it is 3000, then how does  
> the server know to give the request to lighty in the first place?

The browser makes its request to 192.168.0.119:81 and will include the  
information that it is trying to access, for example, myapp.foo.bar.  
Thus the request arrives at lighty. I’m not familiar with how you  
configure lighty, but somewhere in its configuration it will need the  
information that requests for “myapp.foo.bar” need to be forwarded on to  
192.168.0.119:3000. The browser does not know (or need to know) the  
port number of the mongrel process(es) behind lighty. Indeed, you  
wouldn’t want it to know because you might want to change the number or  
location of the mongrel processes.

HTH  
John

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 17, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/5 "2007-08-17T12:51:10Z")

</div>

Hi,

John W. wrote:

> The browser makes its request to 192.168.0.119:81 and will include the  
> information that it is trying to access, for example, myapp.foo.bar.  
> Thus the request arrives at lighty. I’m not familiar with how you  
> configure lighty, but somewhere in its configuration it will need the  
> information that requests for “myapp.foo.bar” need to be forwarded on to  
> 192.168.0.119:3000.

That’s quite easy. The relevant part of the lighttpd.conf would look  
something like this.

server.modules = (

# …

“mod\_proxy”,

# …

)

# The first application is served by a mongrel on port 3000.

$HTTP[“host”] =~ “[foo.example.com](http://foo.example.com)” {

# …

proxy.server = ( “/” =\>  
((“host” =\> “127.0.0.1”, “port” =\> 3000)))  
}

# The second application is served by two mongrels on port 3000.

$HTTP[“host”] =~ “[bar.example.com](http://bar.example.com)” {

# …

proxy.server = ( “/” =\>  
((“host” =\> “127.0.0.1”, “port” =\> 3000),  
(“host” =\> “127.0.0.1”, “port” =\> 3001)))  
}

Take a look at [http://trac.lighttpd.net/trac/wiki/Docs%3AModProxy](http://trac.lighttpd.net/trac/wiki/Docs%3AModProxy) for  
details concerning the configuration of mod\_proxy under lighttpd.

Lutz

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 29, 2007, 3:04am UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/6 "2007-08-29T03:04:42Z")

</div>

Sorry for the bump - I’m just getting to the point where I can sort of  
understand this. One question: What do “host” and “[bar.example.com](http://bar.example.com)”  
signify in the $HTTP line? Does this mean, for example, that I can set  
“host” to an arbitrary network address, like 192.168.0.333? Or  
“[bar.example.com](http://bar.example.com)” to an arbitrary domain name?

For example, if I have two applications, and I want to separate them so  
that one will run at 192.168.0.300, and the other will run at  
192.168.0.301, is this where I set this?

Thanks, and sorry of this confuses. I’m a little confused myself.  
sean

> Lutz H. wrote:
> 
> > # The second application is served by two mongrels on port 3000.
> > 
> > $HTTP[“host”] =~ “[bar.example.com](http://bar.example.com)” {
> > 
> > # …
> > 
> > proxy.server = ( “/” =\>  
> > ((“host” =\> “127.0.0.1”, “port” =\> 3001),  
> > (“host” =\> “127.0.0.1”, “port” =\> 3002)))  
> > }

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [August 17, 2007, 12:52pm UTC](https://www.ruby-forum.com/t/multiple-apps-on-one-lighty-server/112195/7 "2007-08-17T12:52:28Z")

</div>

Silly me:

Lutz H. wrote:

> # The second application is served by two mongrels on port 3000.
> 
> $HTTP[“host”] =~ “[bar.example.com](http://bar.example.com)” {
> 
> # …
> 
> proxy.server = ( “/” =\>  
> ((“host” =\> “127.0.0.1”, “port” =\> 3000),  
> (“host” =\> “127.0.0.1”, “port” =\> 3001)))  
> }

This must be like this, of course

proxy.server = ( “/” =\>  
((“host” =\> “127.0.0.1”, “port” =\> 3001),  
(“host” =\> “127.0.0.1”, “port” =\> 3002)))

Lutz
