[Zope] Virtualhost monster problems

Oliver Bleutgen myzope@gmx.net
Mon, 13 May 2002 19:13:51 +0200


Sorry for me not sipping, I'am in a hurry...

Wayne Pascoe wrote:
> On 13/5/02 3:24 pm, "Oliver Bleutgen" <myzope@gmx.net> wrote:
>  
> 
>>><VirtualHost *>
>>>    RewriteEngine On
>>>    RewriteCond %{HTTP_HOST} ^.*$
>>>   RewriteRule ^/(.*)
>>>http://127.0.0.1:8080/VirtualHostBase/http/%{HTTP_HOST}:80/$1 [L,P]
>>>
>>This won't work when a client includes the port in the host header,
>>like Host: zaphod-content.mydomain.com:80.
>>Some clients do that, wget for instance, and you'll get an extra ":80"
>>in your request to zope.
>>
> 
> Ah, ok. The reason I did this is that the original had
> RewriteCond %{HTTP_HOST}:80 ^.*$ and this only worked if I included the :80
> in my browser line.

Well, you need to do both, in one way or other.
If you want the flexibility of variable HTTP_HOSTs, you need to cope 
with the fact that HTTP_HOST may be sent with or without the port tacked 
at the end of the hostname. This can be done with two RewriteConds + 
different following RewriteRules, something like (untested, wrapped)

RewriteCond &{HTTP_HOST} ^.*:80$
RewriteRule http://127.0.0.1:8080/VirtualHostBase/http/%{HTTP_HOST}/$1 [L,P]
RewriteRule ^/(.*)
http://127.0.0.1:8080/VirtualHostBase/http/%{HTTP_HOST}:80/$1 [L,P]

You should really read up about mod_rewrite, because, reading it again, 
I have no idea what effect your RewriteCond line should have. Seems to 
me it matches always.
Here it filters if HTTP_HOST has a trailing ":80" and rewrites accordingly.
If there's no trailing ":80" the second RewriteRule comes into effect.

Thinking about it, I had emailed the author about this thing and it 
seems he just didn't quite adapt his howto correctly to the host-header 
"problem".
The 3 lines above should do the trick.



> 
> 
>>><IfModule mod_proxy.c>
>>>    ProxyRequests On
>>>
>>Are you sure you want that?  You now have open your server as a proxy
>>for the whole world, if no other access rules are installed.
>>You don't need that for what you describe here, see
>>http://httpd.apache.org/docs/mod/mod_proxy.html#proxyrequests
>>
> 
> My main reason for including that is that the zope document I read at
> http://www.zope.org/Members/Jace/apache-vhm said I should include those
> lines. I shall remove it. Thanks for the tip :)

Once, I tried to contact the authors of the various apache+zope howtos 
which did do that wrong, but didn't find always contacts. It would be 
nice if you could inform that guy about this problem.

> 
> 
>>>Any ideas why the contents of zaphod-content.mydomain.com are not being
>>>served as / when I request it as zaphod-content.mydomain.com ?
>>>
>>Well, it seems that your rule doesn't match. I would enable logging for
>>mod_rewrite (see docs for how to do that) and see what the rewrite
>>
> 
> I have done this at a rewriteloglevel of 3 and I get the following output:
> 
> sd213.52.146.197 - - [13/May/2002:15:27:30 +0100]
> [zaphod-content.mydomain.com/sid#80dd578][rid#8134048/initial] (2) init
> rewrite engine with requested uri /
> 213.52.146.197 - - [13/May/2002:15:27:30 +0100]
> [zaphod-content.mydomain.com/sid#80dd578][rid#8134048/initial] (3) applying
> pattern '^/(.*)' to uri '/'
> 213.52.146.197 - - [13/May/2002:15:27:30 +0100]
> [zaphod-content.mydomain.com/sid#80dd578][rid#8134048/initial] (2) rewrite /
> -> 
> http://127.0.0.1:8080/VirtualHostBase/http/zaphod-content.mydomain.com:80/
> 213.52.146.197 - - [13/May/2002:15:27:30 +0100]
> [zaphod-content.mydomain.com/sid#80dd578][rid#8134048/initial] (2) forcing
> proxy-throughput with
> http://127.0.0.1:8080/VirtualHostBase/http/zaphod-content.mydomain.com:80/
> 
> 
> This to me looks correct. The request is being translated to
> http://127.0.0.1:8080/VirtualHostBase/http/zaphod-content.mydomain.com:80/
> 
> Or is this not what it should be proxied to ?

Ahh, now I see. No it isn't the right thing to do. Darn, forget the 
rules I wrote above, but the concept still holds.  You should rewrite to

http://127.0.0.1:8080/zaphod-content.mydomain.comVirtualHostBase/http/zaphod-content.mydomain.com:80/

with a VHM in the folder zaphod-content.mydomain.com.
This is, because you still have to get into the right folder in zope, 
that work isn't done by VHM.
To do that with the flexibility of HTTP_HOST - so it would work with any 
A record of your domain just by creating a folder with the right name 
and a VHM in it - needs some work with the HTTP_HOST cause of the 
":80-problem".
But if you have one static host and filter the subdomains via other 
means (say apache name-based VirtualHosts), and you have just one 
hostname per virtual host, one line is enough:

RewriteRule ^/(.*) 
http://localhost:40080/zaphod-content.mydomain.com/VirtualHostBase/http/zaphod-content.mydomain.com:80/VirtualHostRoot/$1

For further needs, I recommend reading up about mod_rewrite on 
httpd.apache.org.

cheers,
oliver