[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

WEBrick: Virtual hosts and inherited directory mappings

Lloyd Zusman

2/21/2005 11:13:00 PM

I posted the following query to the webrick mailing list, but that list
has not been very active lately, and so I'm also posting it here, in the
hopes of reaching more WEBrick users:

I'm using the virtual host mechanism of WEBrick, and I'm trying to make
use of shared directories. I'm not sure what is the best way to do
this, and I'm wondering if you folks could give me recommendations.

Here's what I'm doing:

I create a main server which is an instance of WEBrick::HTTPServer.
Then, I create a number servers for my virtual hosts. Each of these is
is also an instance of WEBrick::HTTPServer. I then use the
#virtual_host method to connect these to the main server.

I want these virtual hosts to inherit directory mappings from the main
server, or from some sort of central resource.

For example:

mappings for main server (mainserver.com):

/img => /var/www/img
/icons => /var/www/icons

mappings for virtual host 1 (virthost1.com):

/img => /var/www/virthost1/img

mappings for virtual host 2 (virthost2.com):

/icons => /var/www/virthost2/icons

mappings for virtual host 3 (virthost3.com):

[none]

Summary:

I want virtual host 1 to inherit the /icons mapping from
the main server.

I want virtual host 2 to inherit the /img mapping from
the main server.

I want virtual host 3 to inherit both the /img and /icons
mappings from the main server.

In other words:

mainserver.com/img => /var/www/img
mainsercer.com/icons => /var/www/icons

virthost1.com/img => /var/www/virthost1/img
virthost1.com/icons => /var/www/icons

virthost2.com/img => /var/www/img
virthost2.com/icons => /var/www/virthost2/icons

virthost3.com/img => /var/www/img
virthost3.com/icons => /var/www/icons

I don't want to have to specify the inherited mappings for each virtual
host. That way, if I happen to change the mappings for the main server,
these changes will automatically be seen and used by the virtual hosts.

How would you folks recommend that I do this via webrick?

Thanks in advance.


--
Lloyd Zusman
ljz@asfast.com
God bless you.



4 Answers

GOTOU Yuuzou

2/22/2005 10:11:00 PM

0

Lloyd Zusman

2/22/2005 11:03:00 PM

0

GOTOU Yuuzou <gotoyuzo@notwork.org> writes:

> In message <m3ekf9qzmp.fsf@asfast.com>,
> `Lloyd Zusman <ljz@asfast.com>' wrote:
>> I posted the following query to the webrick mailing list, but that
>> list has not been very active lately, and so I'm also posting it
>> here, in the hopes of reaching more WEBrick users:
>
> I'm really sorry to post this too late.

There is no apology necessary. I posted here a short time after I
posted to the WEBrick mailing list, and I did so solely because there
seem to be just a few posters on that list. My only intention was to
reach the maximum number of people with my query.

I'm sorry if my comment sounded like a complaint, because that was not
my intent.


> [ ... ]
>
> I considered your need is that all 404 requests to virtual
> hosts should be reprocessed by mainserver. I hope the
> following code helps you.

Yes, it does. Thank you! This will definitely do what I want.

By looking at this, I see what seems to be a key aspect of WEBrick that
I previously did not understand. It seems to be the case that in order
to invoke the functionality of one service/servlet from another, all we
have to do is call the #service method of the second service/servlet
from that of the first one. Correct?

If this indeed is the case, I now see how I can do a lot more with
WEBrick.

I very much appreciate your reply and your very useful help with this
excellent piece of software.


> require "webrick"
>
> class FallbackEnabledHTTPServer < WEBrick::HTTPServer
> def service(req, res)
> begin
> super(req, res)
> rescue WEBrick::HTTPStatus::NotFound => ex
> # resume request's attributes and invoke the fallback server.
> req.script_name = ""
> req.path_info = req.path.dup
> @config[:FallbackServer].service(req, res)
> end
> end
> end
>
> httpd = WEBrick::HTTPServer.new(
> :Port => 8080,
> :ServerName => "mainserver.com",
> :DocumentRoot => "./var/www"
> )
> httpd.virtual_host(
> FallbackEnabledHTTPServer.new(
> :Port => 8080,
> :ServerName => "virthost1.com",
> :DocumentRoot => "./var/www/virthost1",
> :FallbackServer => httpd,
> :DoNotListen => true
> )
> )
> trap(:INT){ httpd.shutdown }
> httpd.start


--
Lloyd Zusman
ljz@asfast.com
God bless you.



GOTOU Yuuzou

2/23/2005 3:24:00 AM

0

Lloyd Zusman

2/23/2005 12:37:00 PM

0

GOTOU Yuuzou Wrote:

> In message <m3acpwnqs6.fsf@asfast.com>,
> `Lloyd Zusman <ljz@asfast.com>' wrote:
> > By looking at this, I see what seems to be a key aspect of
> > WEBrick that I previously did not understand. It seems to be
> > the case that in order to invoke the functionality of one
> > service/servlet from another, all we have to do is call
> > the #service method of the second service/servlet from that
> > of the first one. Correct?
>
> Yes. Some utility methods (get_instance for servlets, #[]
> and #access_log for virtual servers) are also required in
> order to work completely.

Thank you.

On a related subject, do you or anyone else here know of a way within
WEBrick to make Tofu and a FileHandler work together? I'd like to be
able to maintain sessions when using a FileHandler, and to access
session variables within ERb (in *.rhtml files).

Any ideas?

Thanks again.

--
Lloyd Zusman
ljz@asfast.com
God bless you.