name_based_virtual_hosts

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: Re: proxying name-based virtual hosts
From: Dan Rench <drench@i-works.com>
Date: Thu, 10 Aug 2000 12:08:53 -0500 (CDT)

On Thu, 10 Aug 2000, Roger Espel Llima wrote:

> I'm trying to set up a proxy front-end server to my heavy mod_perl
> backend, and I'm having some trouble with name-based virtual hosts.
> 
> Basically, with a rule like "RewriteRule ^/(.*) http://10.36.1.10/$1 [P]",
> the proxy sends an http request to 10.36.1.10:80, but setting the Host:
> http header to "10.36.1.10", not what the client supplied.
> 
> The mod_perl guide suggests having <VirtualHost> statements on the
> front-end, and redirecting each hostname to a different port on the
> backend.  This is inconvenient for me, because I'd have to change the
> app logic on the backend (which currently uses $r->header_in("Host")
> directly).
> 
> Ideally, what I'd like is to have the front-end server not check or
> touch Host: at all, and pass it unaltered to the backend, which knows
> what to do with it.  Does anyone know of a way to do this?
> 
> If that's not possible, I'd settle for the backend getting it in a new
> header (eg. X-Original-Host), using an approach similar to
> mod_proxy_add_forward.c.

I ended up adding this to mod_proxy_add_forward.c:

ap_table_set(r->headers_in, "X-Original-Host",
    ap_table_get(r->headers_in, "Host"));

(right after the line that adds the "X-Forwarded-For" header).

Then on the backend, I've got a TransHandler that essentially does an
$r->headers_in->set('Host' => $r->header_in('X-Original-Host')),
along with setting $r->connection->remote_ip to the "X-Forwarded-For"
header.  I should note that it only does this if it "trusts" these
headers, in my case if the request is coming from 127.0.0.1 I trust it.

A nice plus is that the mod_perl backend server acts the same way
whether there's a proxy in front of it or not.

BTW I haven't tried this, but I would have had I not already had something
in place, since it's more flexible:

http://forum.swarthmore.edu/epigone/modperl/lolkahcling/Pine.LNX.4.04.10008031341330.4313-200000@neutrino.activespace.com

===

Subject: Apache not finding Virtual Host doc (What's the trick?)
From: wilson@claborn.net (Jonathan Wilson)
Date: Tue, 12 Sep 2000 11:40:14 -0500

Well, I'm trying to set up this virtual host,  and I'm getting "Forbidden" 
messages:

here, I'm using the IP directly:

Forbidden
You don't have permission to access / on this server
________________________________________________________
  Apache/1.3.12 Server at bogus_host_without_reverse_dns Port 80

Here's my directory listing:
[admin@claborn1 admin]$ ls -ld /Webhomes
drwxrwxr--    4 admin    cscadmin     1024 Sep 12 11:14 /Webhomes
[admin@claborn1 admin]$ ls -ld /Webhomes/Test/
drwxrwxr-x    2 admin    cscadmin     1024 Sep 12 11:20 /Webhomes/Test/
[admin@claborn1 admin]$ ls -l /Webhomes/Test/
total 2
-rw-rw-r--    1 admin    cscadmin      142 Sep 12 11:20 index.html

And the VHost enty in /etc/httpd/conf/httpd.conf:


<VirtualHost 216.234.228.94>
     ServerAdmin webmaste@localhost
     DocumentRoot /Webhomes/Test
     ErrorLog logs/Test-error_log
     CustomLog logs/Test-access_log common
</VirtualHost>


Does anyone see what's wrong? It DocumentRoot for the server it 
/home/httpd/html but does that matter?

And of course I've restarted the server with /etc/rc.d/init.d/httpd restart

Any help would be greatly appreciated

===

Subject: Re: Nevermind:  Apache not finding Virtual Host doc (What's
From: wilson@claborn.net (Jonathan Wilson)
Date: Tue, 12 Sep 2000 12:42:52 -0500

Forget that - I forgot to +x the silly directory (shoulda known....)

===

Subject: Re: Apache not finding Virtual Host doc (What's the trick?)
From: burk@pobox.com
Date: Tue, 12 Sep 2000 14:26:45 -0400 (EDT)

On Tue, 12 Sep 2000, Jonathan Wilson wrote:

Assuming you are using a name and not IP address based virtual host....

Do you have the NameVirtualHost directive in your httpd.conf?

NameVirtualHost 216.234.228.94

By hitting the server with the IP address, instead of the URL, you defeat
apache's ability to distinguish name based virtual hosts. In my
experience, it will load the first Name based virtual host loaded in the
conf file.


> Does anyone see what's wrong? It DocumentRoot for the server it 
> /home/httpd/html but does that matter?

No, it should, in fact, be ignored.

Hope this helps
-burk


===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu