Apache front-ended Zope/Plone including Apache-style userdirs
To set up Plone, I wanted to make sure that I could continue to use other web applications, such as PHP and Java applications. This can be accomplished using Apache with mod_proxy and mod_rewrite. I'll cover this from an Ubuntu perspective, but setting this up on other distributions or operating systems should be similar. While Ubuntu spreads the configuration to many different files, on many other systems you can put all the configuration lines I mention below directly into http.conf.
Install Apache
Start by installing Apache 2.
On Ubuntu:
sudo apt-get install apache2
You may already have Plone set up, but if you don't, install it.
On Ubuntu:
sudo apt-get install plone plone-site
Enabling mod_rewrite and mod_proxy
Next, we need to enable mod_proxy and mod_rewrite. Simply put, mod_rewrite lets you point a URL at another URL. mod_proxy lets you point a url at another server on another port. mod_proxy serves as a translator, so the user never actually talks to any other port than 80. With mod_proxy your user can go from Plone to a PHP app to a Java app and never know it.
On Ubuntu
sudo a2enmod proxy
sudo a2enmod rewrite
Next we edit the mod_proxy config.
sudo gedit /etc/apache2/mods-enabled/proxy.conf
Now, find the following settings and match what I have here. Follow this exactly, or you could end up with an open proxy that lets others bounce through your machine to get to anywhere they want anonymously, send spam, etc. Whatever you do, never turn ProxyRequests to on.
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
#Deny from all
Allow from all
</Proxy>
Zope Rewrite Rule
Next we need to set up our rewrite rules.
sudo gedit /etc/apache2/sites-enabled/000-default
Just before the ending virtual host tag, </VirtualHost>, add these lines:
#Rewrites
RewriteEngine on
# Root of website goes directly to Zope.
RewriteRule ^/(.*) http://localhost:8081/$1 [P]
Rewrite Rules For Other Applications
If you have other applications that you want to serve, you need a rewrite rule for those, and it needs to go before the Zope ~/(.*) rewrite rule, but after the RewriteEngine On. If they run in Apache, such as PHP apps, the you can use a Local directive. For instance, here's my Squirrelmail directive:
# Let the mail pass through for Squirrelmail
RewriteRule ^/mail/(.*) - [L]
RewriteRule ^/mail - [L]
Unfortunately this messes up the Plone mail icon. To fix that, we add a line before the ~./mail directive:
# Rule for Plone mail icon.
RewriteRule ^/mail_icon.gif http://localhost:8081/mail_icon.gif [P]
Or here's an example of proxying access to my gnump3d server.
RewriteRule ^/mp3(.*) http://localhost:9000/ [P]
If you have a Java app server, you can use this in concert with mod_jk, which is a big subject I'd rather cover in another entry in the future.
Userdirs
Before setting up Plone, I published some of my stuff in an Apache userdir. mod_userdir sets up those user directories on a web server that start with a tilde, ~. For instance, my userdir was at http://dmartin.org/~dmartin. When I moved to Plone, I copied all that content into my Plone Members folder, but I wanted to maintain those userdir links I have published elsewhere on the web. To accomplish this, I add this line before the Zope ~/(.*) rewrite rule.
# Rule for Plone mail icon. Yes, it is necessary. :(
RewriteRule ^/mail_icon.gif http://localhost:8081/mail_icon.gif [P]
Restarting Apache
Once we've made these changes to the configuration we need to reload Apache. On Ubuntu:
sudo /etc/init.d/apache2 reload
Zope Virtual Hosting
Finally, we need to set up Zope's virtual hosting. What this will allow us to do is control which Plone site sits at the base of our web server. First, log into the Zope Management Interface (ZMI), probably at http://localhost/manage. Find the virtual_hosting node. It should exist on most Plone installations, but if it doesn't, add a "Virtual Hosting Monster" to the root of your Zope site. Once in the virtual_hosting, switch to the Mappings tab. Add these lines:
example.com/example-plone-site
www.example.com/example-plone-site
zope.example.com/
But replace my example.com with your own site, and replace example-plone-site with the name of your Plone sub-site. What these settings do is move the site root. if someone comes to example.com, they see the Plone site at /example-plone-site, without seeing the subdirectory. This also means you can host multiple Plone sites on the same machine, but with different domain names. So, you could register a second domain example2.com pointed at the same machine, and visitors would see a different Plone site at /example2-plone-site if you added a mapping:
example2.com/example2-plone-site
www.example2.com/example2-plone-site
The zope.example.com site is significant, and absolutely critical for people who remotely manage their Zope server. Since you've redirected example.com to a subsite, there would be now be no way for you to manage the master Zope server, because if you go to http://example.com/manage the virtual host mapping proxies you to http://example.com/example-plone-site/manage. Using the zope.example.com directive I gave you, you can manage your Zope parent site at http://zope.example.com/manage. If you locally manage the Zope server this line isn't as important since we didn't add a mapping for localhost.
Conclusion
So, that's it. You should now see your Plone site at http://example.com and http://www.example.com. No port, no subdirectory. You also have userdirectories, such as http://example.com/~myusername.
- dmartin's blog
- Add new comment
- 1664 reads
Weblog