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.tld on port 80
  • your Plone site is named Plone at 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.

flip-flop: Plone inside an apache directory

Posted by Kurt Bendl at May 11, 2006 06:47 AM
Thanks Cameron. This got me on the path to solve my reverse problem, how to sprinkle plone sites inside subdirectories of an already established static web site. This and Tirian's "How VHM Works" doc heled me figure out the basic rewrite rule. (Probably simple for uber-geeks, but I beat my head against the wall for 4 hours trying to figure it out.)

**Plone in a sub-folder of an apache site**::

  RewriteRule ^/iplone(.*) \
  http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/iplone/VirtualHostRoot/_vh_iplone$1 [P,L]
 

Apache 2 still not serving

Posted by Mohammed Ibrahim at Sep 21, 2006 10:31 AM
Thanks for this beautiful tutorial. It states my problem perfectly but i followed it and nothing happedned apache still not working. I work under RHEL AS 4, Apache 2 and plone 2.5. Thanks again.

Apache Proxying

Posted by Jeremy D. Weiss at Feb 23, 2007 07:31 PM
A fairly important note: According to the apache website, if the only proxying you're doing is ProxyPass, you should have ProxyRequests OFF, not on. If yo do have it on, you need to set up security rules for it appropriately, or you're runinng an open proxy.

See:
http://httpd.apache.org/[…]/mod_proxy.html#proxypass
http://httpd.apache.org/[…]/mod_proxy.html#proxypass