[ZCM] [ZC] 495/ 2 Comment "Simple virtual host handling"
Collector: Zope Bugs, Features, and Patches ...
zope-coders-admin@zope.org
Fri, 17 Jan 2003 09:05:59 -0500
Issue #495 Update (Comment) "Simple virtual host handling"
Status Pending, Zope/feature+solution medium
To followup, visit:
http://collector.zope.org/Zope/495
==============================================================
= Comment - Entry #2 by regebro on Jan 17, 2003 9:05 am
I agree (but others do not) that the virtual host mappings should be in the Control Panel, but that's a minor issue. :)
However, I'm not sure in what way your patch simplifies virtual hosting. It looks very similar to the way Virtual Host Monster handles it today.
________________________________________
= Request - Entry #1 by Anonymous User on Jul 30, 2002 7:31 am
HTTP implementation in Zope allows virtual host configuration and handling to be simpler than that from VirtalHostMonster.
The attached patch replaces the functionality offered by VirtalHostMonster for Zope running behind Apache. It handles cases where logical path is shorter than physical path and vice versa. I've been using and testing it for a few months already.
I think that if this patch gets into Zope, "Mappings" functionality from VirtualHostMonster should be integrated into Control_Panel.
Below is a sample vhost configuration from httpd.conf:
NameVirtualHost 192.168.0.1:80
FastCgiExternalServer /var/www/fcgi-bin/zope -socket /usr/local/zope/var/zope.sock -pass-header Authorization -idle-timeout 60
# This directory must exist and should be empty
<Directory /var/www/fcgi-bin>
SetHandler fastcgi-script
</Directory>
<VirtualHost 192.168.0.1:80>
ServerName www.foo-site.com
DocumentRoot /var/www/fcgi-bin/zope/foo
Alias /images /var/www/images
# alias for direct access to Zope root folder
Alias /_ /var/www/fcgi-bin/zope
#AliasMatch ^/_(/.*)?$ /var/www/fcgi-bin/zope$1
</VirtualHost>
<Directory /var/www/images>
Options MultiViews
AllowOverride Indexes
Order allow,deny
Allow from all
</Directory>
Unfortunately I'm not authorized to create an attachment as a guest user, so the patch goes below:
--- BaseRequest.py-orig Wed Mar 27 22:51:05 2002
+++ BaseRequest.py Tue Jul 30 11:37:37 2002
@@ -239,6 +239,19 @@
request['TraversalRequestNameStack'] = request.path = path
+ # Handle virtual hosting when behind an Apache
+ env = request.environ
+ virtual_root_pos = None
+ if env.has_key('REQUEST_URI'): # Apache sets REQUEST_URI
+ if env['SCRIPT_NAME']: # logical path is longer than physical path
+ request.setVirtualRoot(env['SCRIPT_NAME'])
+ else: # logical path is shorter or equal to physical path
+ request_uri = env['REQUEST_URI']
+ l = request_uri.find('?')
+ if l<0: l = len(request_uri)
+ virtual_root_pos = env['PATH_INFO'].count('/', 0, -l) or None
+ # when virtual_root_pos==0 (i.e. logical==physical), use None (no virtual host)
+
entry_name = ''
try:
# We build parents in the wrong order, so we
@@ -247,6 +260,14 @@
bpth = getattr(object, '__before_publishing_traverse__', None)
if bpth is not None:
bpth(object, self)
+
+ if virtual_root_pos is not None \
+ and not request.other.has_key('VirtualRootPhysicalPath'): # avoid conflict with other virtual host manager
+ if virtual_root_pos==0:
+ request.setVirtualRoot([])
+ virtual_root_pos = None
+ else:
+ virtual_root_pos-= 1
path = request.path = request['TraversalRequestNameStack']
# Check for method:
==============================================================