You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dan Rench <dr...@i-works.com> on 2000/03/03 19:00:28 UTC
ProxyPass and name-based vhosts
This topic came up before* but I didn't see a solution.
The situation: a mod_perl-dependant Apache serving many name-based virtual
hosts. I want a lightweight proxy in front. The guide calls this "the
difficult case". It was simple enough to add an "X-Original-Host:" header
(by adding 2 lines to mod_proxy_add_forward.c) and have my backend
TransHandler use that instead of "Host:" if it exists.
All I need now is to get mod_proxy to take the client's incoming "Host:"
header into account without resorting to <VirtualHost> sections (which would
defeat the purpose of the backend's fairly complicated TransHandler).
The problem is that mod_proxy's caching scheme makes no distinction between
http://site1/index.html and http://site2/index.html, and that's obviously
not what I want.
I'm willing to dig into the mod_proxy code to try changing this, but if
somebody out there has already done it, I'd rather not reinvent the wheel.
Removing mod_perl from the backend isn't an option. I *might* be able to
recreate the TransHandler with mod_rewrite, but we've got other specialized
handlers dealing with things like authentication that I would really hate
having to rewrite in C. I figure patching mod_proxy is going to be the least
painful solution.
* http://marc.theaimsgroup.com/?l=apache-modperl&m=94479072703344&w=2
Re: ProxyPass and name-based vhosts
Posted by Vivek Khera <kh...@kciLink.com>.
>>>>> "GL" == George Lewis <sc...@schvin.net> writes:
GL> To have the "actual" web server know what name based virtual
GL> host it is getting a request for, I have some extra DNS information
GL> setup. So when a request comes into the proxy server for domain1.com, rather
GL> than forwarding the request to webserver.domain.com, it forwards to
GL> domain1.webserver.domain.com. Similarly, incoming requests for
GL> domain2.com end up at domain2.webserver.domain.com. So with a few
GL> virtualhost additions on the actual web server, things are beautiful.
That's too much work. Just have your proxy forward to different port
numbers on the "actual" server. No DNS hassles.
Re: ProxyPass and name-based vhosts
Posted by George Lewis <sc...@schvin.net>.
I had a similar problem, and I'm not sure if this will help you, but it
worked for me.
I'm using mod_proxy on the front end, with assorted web servers buried
beneath it.
To have the "actual" web server know what name based virtual
host it is getting a request for, I have some extra DNS information
setup. So when a request comes into the proxy server for domain1.com, rather
than forwarding the request to webserver.domain.com, it forwards to
domain1.webserver.domain.com. Similarly, incoming requests for
domain2.com end up at domain2.webserver.domain.com. So with a few
virtualhost additions on the actual web server, things are beautiful.
That way the proxy server still hands it off, and the actual web server
knows what host is actually being requested.
Again, I'm not sure if this is exactly relevant to your question, I
haven't played with the caching features of mod_proxy too much. If you want
more details, let me know.
George
Dan Rench (drench@i-works.com) wrote:
> This topic came up before* but I didn't see a solution.
>
> The situation: a mod_perl-dependant Apache serving many name-based virtual
> hosts. I want a lightweight proxy in front. The guide calls this "the
> difficult case". It was simple enough to add an "X-Original-Host:" header
> (by adding 2 lines to mod_proxy_add_forward.c) and have my backend
> TransHandler use that instead of "Host:" if it exists.
>
> All I need now is to get mod_proxy to take the client's incoming "Host:"
> header into account without resorting to <VirtualHost> sections (which would
> defeat the purpose of the backend's fairly complicated TransHandler).
>
> The problem is that mod_proxy's caching scheme makes no distinction between
> http://site1/index.html and http://site2/index.html, and that's obviously
> not what I want.
>
> I'm willing to dig into the mod_proxy code to try changing this, but if
> somebody out there has already done it, I'd rather not reinvent the wheel.
>
> Removing mod_perl from the backend isn't an option. I *might* be able to
> recreate the TransHandler with mod_rewrite, but we've got other specialized
> handlers dealing with things like authentication that I would really hate
> having to rewrite in C. I figure patching mod_proxy is going to be the least
> painful solution.
>
> * http://marc.theaimsgroup.com/?l=apache-modperl&m=94479072703344&w=2
--
George Lewis
http://schvin.net/
Re: ProxyPass and name-based vhosts
Posted by Dan Rench <dr...@i-works.com>.
I think I solved this (though I need to do more testing to be sure).
A few of the people who replied didn't quite get what I'm trying to do.
I'll try explaining more clearly:
I've got a machine that serves lots of name-based virtual hosts.
I'm using a TransHandler that relies on the incoming "Host:" header from
the client. I want to put a lightweight proxy in front of the mod_perl
vhost box. Using a modified mod_proxy_add_forward, I had the proxy send
the client's original "Host:" header to the backend vhost box via
"X-Original-Host:". It was a simple fix to get my TransHandler to use that
header instead if it's present. The rub was that mod_proxy was not taking
the virtual hostname into account when it was looking in its cache.
It made no distinction between http://host1/x.html and http://host2/x.html .
The suggestion to use mod_rewrite on the proxy to incorporate the hostname
into the URI was OK, but it would have meant making some non-trivial changes
to my TransHandler. Instead I made a little change to mod_proxy.c:
288c288
< char *url, *scheme, *p;
---
> char *url, *scheme, *p, *munged_url;
326c326,327
< rc = ap_proxy_cache_check(r, url, &conf->cache, &cr);
---
> munged_url = ap_psprintf(r->pool, "%s/%s", url, ap_table_get(r->headers_in, "Host"));
> rc = ap_proxy_cache_check(r, munged_url, &conf->cache, &cr);
(sorry if the above got wrapped)
Yes, my "munged_url" is a bit silly (url with "/hostname" tacked on the end).
I would have munged it more nicely but my C skills are very rusty.
It does what I need: it makes the hostname matter for lookups into the
proxy's cache. The "real" url remains intact and gets fetched properly.
BTW, here's my diff for mod_proxy_add_forward.c:
133a134,135
> ap_table_set(r->headers_in, "X-Original-Host",
> ap_table_get(r->headers_in, "Host"));
Re: ProxyPass and name-based vhosts
Posted by Sean Dague <sd...@raleigh.ibm.com>.
Dan,
Maybe I am missing the point or what you need to do, but what about using
mod_rewrite to rewrite the proxied url to the mod_perl server based on
the host header. I recently had to do something allong these lines as
there was a requirement to pass the client's ip address through the proxy
server to the backend mod_perl server.
Maybe this doesn't fit into your framework, but the power of mod_rewrite
is really impressive, and would probably be good to look into anyway.
-Sean
Disclaimer: All statements are IMVHO
Sean Dague
IBM Global Services
E-Business Division
sdague@raleigh.ibm.com
On Fri, 3 Mar 2000, Dan Rench wrote:
> This topic came up before* but I didn't see a solution.
>
> The situation: a mod_perl-dependant Apache serving many name-based virtual
> hosts. I want a lightweight proxy in front. The guide calls this "the
> difficult case". It was simple enough to add an "X-Original-Host:" header
> (by adding 2 lines to mod_proxy_add_forward.c) and have my backend
> TransHandler use that instead of "Host:" if it exists.
>
> All I need now is to get mod_proxy to take the client's incoming "Host:"
> header into account without resorting to <VirtualHost> sections (which would
> defeat the purpose of the backend's fairly complicated TransHandler).
>
> The problem is that mod_proxy's caching scheme makes no distinction between
> http://site1/index.html and http://site2/index.html, and that's obviously
> not what I want.
>
> I'm willing to dig into the mod_proxy code to try changing this, but if
> somebody out there has already done it, I'd rather not reinvent the wheel.
>
> Removing mod_perl from the backend isn't an option. I *might* be able to
> recreate the TransHandler with mod_rewrite, but we've got other specialized
> handlers dealing with things like authentication that I would really hate
> having to rewrite in C. I figure patching mod_proxy is going to be the least
> painful solution.
>
> * http://marc.theaimsgroup.com/?l=apache-modperl&m=94479072703344&w=2
>