How can I put certain webpages on a separate webserver from the rest of the site?
September 14, 2007 4:06 AM   Subscribe

How do I/Can I put certain directories (and pages) on a separate webserver from the rest of the site?

For example. I have http://www.example.com on one server. I wish to have http://www.example.com/directory2 on another server. Also, possibly, http://www.example.com/directory/page3.htm on another server (but not anything else in /directory/). I'd like this to be as transparent/unobvious to the user as possible.

In this particular case, server one is IIS and server two is unix. I'd also be interested to know how to do it if both servers were unix.
posted by Hartster to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
You can do all of this using ISAPI Rewrite which sits on IIS and filters incoming requests. Any which match a given pattern get a range of rewrite commands applied to them. I've used it and I find it's great. I think it does help if you've used mod_rewrite (the Apache equivalent) before as the concepts can be a bit abstruse.

If you take a look at the example marked 'Moving site location' I think that with a more refined regex you'll find that's what you're after.
posted by southof40 at 4:14 AM on September 14, 2007


Just re-read your question - I've sort of covered it anyway but regarding both servers being Unix ... if I may assume that means both servers being Apache then mod_rewrite will do it. Shared hosters often fail to enable mod_rewrite but in any other environment it should be obtainable and does all the stuff (and probably more) which ISAPI Rewrite does.
posted by southof40 at 4:19 AM on September 14, 2007


With Apache, you'd normally use mod_proxy for this, ala:

ProxyPass /mydir http://otherserver/hisdir

or:

<Location /mydir>
 ProxyPass http://otherserver/hisdir
</Location>


In Apache 2.2 you can also load balance across multiple servers with mod_proxy_balancer:

<Proxy balancer://foo>
 BalanceMember http://otherserver1/hisdir
 BalanceMember http://otherserver2/hisdir
</Proxy>

ProxyPass /mydir balancer://foo


You can also use mod_rewrite in conjuction with mod_proxy using the [P] flag for more fine-grained control over it, e.g. only proxying paths starting with a number:

RewriteRule ^/mydir/([0-9]+) http://otherserver/hisdir/$1 [P]
posted by Freaky at 6:22 AM on September 14, 2007


If you want the other directories/files served *directly* by the other webservers, instead of going via the main one, you're going to have to use a different domain, and issue redirects from the main server to the secondary one. In Apache you'd then do:

Redirect permanent /mydir http://otherserver/hisdir

You can also use RedirectMatch with a regexp for more complex redirections. These are more obvious from the client point of view because they result in additional requests to another server, which can introduce latency, and of course the new URL will be visible in the address bar if it's not part of a frame/script/stylesheet/etc in another document.

Proxying is more expensive for the proxying server, since it's having to read and write the response data from another system to the client instead of just passing the buck with a few headers, but this cost is normally pretty negligable. Many high volume sites make use of this sort of thing to link their static webservers with backend farms of application servers.

Dedicated proxies like Varnish, or the more traditional Squid are also often used for this sort of thing.
posted by Freaky at 6:44 AM on September 14, 2007


You might find this post relevant.
posted by kamelhoecker at 12:26 PM on September 14, 2007


« Older Scratch my Bjork itch   |   The sharing of the files; make it so. Newer »
This thread is closed to new comments.