Apache/VHM _and_ AccessRule at the same time
Hi, I'm running into some problems having Apache Rewrite -> Virtual Host Monster and an Access Rule _at the same time_. The Access Rule (which extracts an embedded variable from the URL, similar to http://www.zope.org/Members/4am/SiteAccess2/otheruse ) works fine when I access the Zope Server directly through its IP. The Apache Rewrite/VHM on the other hand works fine as long as I don't access the folder holding the Access Rule. So I assumed both individual settings were alright (see below). But as soon as I access _that_ folder through a domain, I get very weird URLs generated on my pages (which don't work of course): The VirtualHostBase is _not_ removed, and a "/VHost//" is added after it. I'm not sure how to handle this. Here's my configuration: -------------------------- Apache -------------------------- <VirtualHost admin.mydomain.com:80> RewriteEngine On ProxyRequests On CustomLog /cms/Zope/log/zope_access_log combined ErrorLog /cms/Zope/log/zope_error_log RewriteLog /cms/Zope/log/zope_rewrite_log RewriteLogLevel 9 RewriteRule ^/statistics(.*)/ - [L] RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/admin.mydomain.com:80/Interfaces/... [P,L] </VirtualHost> -------------------------- -------------------------- Zope -------------------------- /VHost (Virtual Host Monster) /... /Interfaces/InterfaceAdmin/x /y /Customers/x /y /extractCustomerFromURL (AccessRule) /Subfolder/x /y -------------------------- -------------------------- Access Rule "extractCustomerFromURL" -------------------------- request = container.REQUEST stack = request['TraversalRequestNameStack'] customer_id = stack.pop() request.set('customer_id', customer_id) request.setVirtualRoot(request.steps + [customer_id]) -------------------------- So "/Customers/mycustomer/Subfolder/x" should call "/Customers/Subfolder/x" and set "customer_id" to "mycustomer" in the REQUEST object. "/Customers/Subfolder/x" then uses that customer_id to show corresponding information. If I go to "1.2.3.4:8080/Interfaces/InterfaceAdmin/Customers/mycustomer/Subfolder/x" it works, and if I go (no further down than) "admin.mydomain.com/x", everything's fine as well. But "admin.mydomain.com/Customers/mycustomer" (and of course anything further down, i.e. .../Subfolder/x) don't work as expected. For example a link to the subfolder .../Accounts/hisaccount (which I build with container['Accounts'].absolute_url() + '/hisaccount') will come out as: http://admin.mydomain.com/Interfaces/InterfaceAdmin/VHost///Customers/mycust... The domain is kept, but the VirtualHostRoot /Interfaces/InterfaceAdmin remains, and "/VHost//" is appended to it. (A REQUEST dump said exactly that same thing...) Does anyone have an idea on how to solve this? What exactly is "Virtual Host Monster" (yes the VHM in the Zope root has the id "VHost" :-)) doing to the virtual root and how can I work with it as intended? Ideally, a solution would work both ways - IP and domain-based. But I'm ready to sacrifice the IP-based access if only the domain rewriting would work with my Access Rule... :-( Any help highly appreciated, thank you very much in advance, Danny P.S.: Please "Reply All" to include my address since I am currently not a subscriber of zope@zope.org... Cheers.
I'll take a crack at this. On Sun, 2003-06-15 at 17:33, Danny W. Adair wrote:
Here's my configuration:
-------------------------- Apache -------------------------- <VirtualHost admin.mydomain.com:80> RewriteEngine On ProxyRequests On
First, you do NOT want ProxyRequests on for what you're doing here. This directive has nothing to do with being a "reverse" proxy, it is a directive for configuring Apache as an outbound HTTP proxy. Bad idea, unless that's what you're intending to do.
customer_id = stack.pop()
I suspect this is your problem. I don't have time to trace out the whole thing, but you're popping the last item off the traversal stack without (it appears) doing any checking to see if the last item is actually what you think it is. You may want to check if stack[-1] matches a customer_id before popping it off or step backward through your stack looking for a value that does match. HTH, Dylan
Thank you Dylan, At 10:02 AM 6/16/2003 -0700, Dylan Reinhardt wrote:
I'll take a crack at this.
On Sun, 2003-06-15 at 17:33, Danny W. Adair wrote:
Here's my configuration:
-------------------------- Apache -------------------------- <VirtualHost admin.mydomain.com:80> RewriteEngine On ProxyRequests On
First, you do NOT want ProxyRequests on for what you're doing here. This directive has nothing to do with being a "reverse" proxy, it is a directive for configuring Apache as an outbound HTTP proxy. Bad idea, unless that's what you're intending to do.
I just copied that whole VirtualHost section from the server config. (Someone else set it up) I don't know what the ProxyRequest directive actually does :-). Thanks for the insight, I passed that on; might have been a mistake.
customer_id = stack.pop()
I suspect this is your problem.
I don't have time to trace out the whole thing, but you're popping the last item off the traversal stack without (it appears) doing any checking to see if the last item is actually what you think it is.
You may want to check if stack[-1] matches a customer_id before popping it off or step backward through your stack looking for a value that does match.
I left that part out, that's why I said it "basically looks like this". I do check if the last item on the stack is a valid customer_id. But I get that weird behavior even when passing correct items. See Ethan's email, I think he knows what the problem is. Thanks again, Danny
HTH,
Dylan
On Mon, 2003-06-16 at 13:47, Danny W. Adair wrote:
I don't know what the ProxyRequest directive actually does :-).
If you're curious: http://httpd.apache.org/docs/mod/mod_proxy.html#proxyrequests Dylan
Danny W. Adair wrote:
I'm running into some problems having Apache Rewrite -> Virtual Host Monster and an Access Rule _at the same time_.
Unfortunately, VHM and your Access Rule are fighting over the virtual root, and VHM is losing. Setting the virtual root was never really a good way to handle this sort of thing anyway, and I plan to add a set of methods in Zope 2.7 that will do it properly. For now, I recommend patching your ZPublisher/HTTPRequest.py to add the following method just above setVirtualRoot(): def appendToPath(self, path): """ Append path elements used to construct URLs. """ self._steps.extend(map(quote, path)) self._resetURLS() ...and changing your Rule to: stack = request['TraversalRequestNameStack'] customer_id = stack.pop() request.set('customer_id', customer_id) request.appendToPath([customer_id]) Cheers, Evan @ 4-am
Danny W. Adair wrote at 2003-6-16 12:33 +1200:
... I'm running into some problems having Apache Rewrite -> Virtual Host Monster and an Access Rule _at the same time_. .... -------------------------- Access Rule "extractCustomerFromURL" -------------------------- request = container.REQUEST stack = request['TraversalRequestNameStack'] customer_id = stack.pop() request.set('customer_id', customer_id) request.setVirtualRoot(request.steps + [customer_id])
You AccessRule should almost surely not use "setVirtualRoot" but modify "stack" directly. Otherwise, it interferes with the "virtual root" set by VHM. Dieter
Thank you Dieter, At 10:57 PM 6/16/2003 +0200, Dieter Maurer wrote:
Danny W. Adair wrote at 2003-6-16 12:33 +1200:
... I'm running into some problems having Apache Rewrite -> Virtual Host Monster and an Access Rule _at the same time_. .... -------------------------- Access Rule "extractCustomerFromURL" -------------------------- request = container.REQUEST stack = request['TraversalRequestNameStack'] customer_id = stack.pop() request.set('customer_id', customer_id) request.setVirtualRoot(request.steps + [customer_id])
You AccessRule should almost surely not use "setVirtualRoot" but modify "stack" directly. Otherwise, it interferes with the "virtual root" set by VHM.
Yep, I realize that now. :-) I just copied from the "session variable" example, which doesn't mention possible interference with an existing VHM. Cheers, Danny
Dieter
participants (4)
-
Danny W. Adair -
Dieter Maurer -
Dylan Reinhardt -
Evan Simpson