From: Lloyd Zusman Date: 2005-02-23T08:02:39+09:00 Subject: Re: WEBrick: Virtual hosts and inherited directory mappings GOTOU Yuuzou writes: > In message , > `Lloyd Zusman ' 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.