Mixing Local Apache and Proxyed Content
Many people run Plone proxied behind Apache, but this will generally stop you from serving stuff, like images or PHP, from that Apache server. This howto will show you how to make certain URLs resolve to local Apache resources, even if Plone is proxied/rewritten to the root of the domain.
In the simplest instance of making Apache front Plone, you'll have a VirtualHost or something that contains at least the following directives:
DocumentRoot /tmp ProxyRequests On ProxyPass /zoperoot http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/VirtualHostRoot/_vh_zoperoot ProxyPassReverse /zoperoot http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/Plone/VirtualHostRoot/ ProxyPass / http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/Plone/VirtualHostRoot/ ProxyPassReverse / http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/Plone/VirtualHostRoot/
The first pair of proxy statements is for getting to the root of your Zope instance; otherwise, you'll have to disable your VHM by adding a certain string to your URL. It's not necessary, but it's handy. There are other ways, to do this, however: different ports (like the Plone installers) and different subdomains (like manage.mysite.tld). But you have to have more control over your environment to do that.
Here we assume, by the way, that:
- your domain is
www.mysite.tldon port 80 - your Plone site is named
Ploneat the Zope root (so/Plone) - your Zope instance is running on port
8080
It your setup differs, change these elements. The domain will almost always be different, and the Plone site object is likely to be different, though this is the default in some installers.
But let's say that you want to serve images from your filesystem to http://www.mysite.tld/images. With the above setup, you can't do that: the proxy totally takes over at the root. Every path we ask for is proxied to our Plone server, and so Apache can never serve anything. We even set the DocumentRoot to /tmp in recognition of that: it could be anything, since it's never used. We can use the rewrite engine to do the same thing with regard to proxying to Zope, but allow a hole in the rewriting so that Apache can do its thing in certain places.
Here's a new setup:
DocumentRoot /var/www/ RewriteEngine On RewriteRule ^/zoperoot(.*) http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/VirtualHostRoot/_vh_zoperoot$1 [P,L] RewriteRule ^/pages - [L] RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/www.mysite.tld:80/Plone/VirtualHostRoot/$1 [P,L]
We set our DocumentRoot to the normal location. We have an images/ subdir there with our images in it (or maybe a PHP application, or anything else.) We then convert the proxy statements to rewrite statements. The first matches any incoming requested path with /zoperoot and rewrites it to the Zope root by way of VHM. The /zoperoot could be any path, really, but the rest is pretty strict. It proxies this (the P in the square brackets) and doesn't do any more rewriting (the L in the square brackets).
Next is where the magic comes in. The final RewriteRule matches all incoming paths not previously rewritten (like zoperoot) and proxy-rewrites them to the Plone site. The ones above it, however, might interrupt the process. In this example, anything matching /pages is not rewritten (the dash means this), and the L again stops the rewrite chain. So if the parth does start with images, there will be no rewrite at the root of the domain, and Apache will be asked to serve like normal. Otherwise, it'll proxy to Zope.
