Thursday, December 4, 2008

Managing Apache virtualhosts and squid with iw.recipe.squid

I have a number of plone sites on a server, generally one site is associated with one zope instance. I am using buildout and iw.recipe.squid to add easily a new virtualhost with squid proxying. Im my case the server is running Ubuntu server 8.04, but this should apply without change to a Debian server. This may look overkill for juste one or two sites, but in my case I may have up to 30 different sites (of course all zope instances are not on localhost!).

Let's suppose I have these sites:
  • www.site1.net, zope instance on localhost (127.0.01) port 8080, plone path is located at /site1/portal
  • www.someothersite.com, zope instance on 10.2.0.5 port 9080, plone path /somepath/portal
buildout.cfg:

[buildout]
parts = squid
versions = versions

[versions]
iw.recipe.squid = 0.9

[squid]
recipe = iw.recipe.squid
squid_owner = proxy
squid_visible_hostname = myservername
squid_cache_dir = /var/cache/squid
squid_log_dir = /var/log/squid

squid_accelerated_hosts =
www.site1.net: 127.0.0.1:8080/site1/portal
www.someothersite.com: 10.2.0.5:9080/somepath/portal
After running buildout for the first time:
  • make a symbolic link "/etc/squid.conf" pointing to parts/squid/etc/squid.conf
  • run "bin/squidctl createswap" if required
  • check that squid starts normally and that helper processes are running, too (iRedirector.py, squidAcl.py, squidRewriteRules.py)
After having added one or more site:
  • in /etc/apache2/sites-available create a symbolic link for all config files located in parts/squid/apache. In our case they should be named "vhost_www.site1.net_80.conf", etc
  • run a2ensite to active sites ("a2ensite vhost_www.site1.net_80.conf")
  • reload apache
Adding a new site will be just a matter of adding a new line in squid_accelerated_hosts, running buildout, making the symbolic links and reloading apache.

As of iw.recipe.squid 0.9, squid and apache log reside in the same directory, but the next release should allow to have different directory; it should also allow you to set "combined" rather than "common" log format for apache.

Of course do not forget to configure properly CacheSetup on every plone site.