You are not logged in Log in Join
You are here: Home » Members » itamar » Using Squid to serve Zope pages

Log in
Name

Password

 

Using Squid to serve Zope pages

Squid, the well know HTTP proxy, can also be used as a reverse proxy in front of Zope.  That is, instead of users connecting to Zope, they'll connect to Squid (although they won't know that!).

Why this is good:

  1. Any static content (Images, Files, or your owne DTML pages if they the correct HTTP headers) is going to get served from Squid.  Squid is way faster than Zope!
  2. If Zope dies, the non-dynamic parts of your site will still work, so you have a bit more leeway in getting Zope back up :)
Why this is bad:
  1. You'll have to use Squid's access logs to count how many visitors you had, and Squid doesn't store the Referer or User-Agent headers in it's access log.


Anyways, here's how you do it:
 

  1. Add HTTP headers to your static DTML pages so that they get cached.  I'm going to write a separate Howto on this.
  2. Install Squid:

    Download the latest version from  http://www.squid-cache.org .
    tar xvfz squid-X.tar.gz
    cd squid-X
    ./configure
    make
    su
    make install

    Unless you changed the defaults, squid is now installed in /usr/local/squid.
  3. We'll have Squid running on port 80, so when people connect to our website (http://www.example.com) they'll go straight to Squid, and won't even know that Zope is running on port 8080.  This means squid must run as root.  We therefore need to set the right permissions on squid's directorys - when squid runs as root it gets changed to run as nobody.

    cd /usr/local/squid
    bin/squid -z # this sets up the cache directories
    chown -R nobody.nobody cache
    mkdir logs # may not be neccesary
    chown -R nobody.nobody logs
  4. Next, we need to setup squid so it runs as a http-accelerator, save its logs in standard webserver format instead of it's own format, and of course let the public view our site.

    The squid configuration file in /usr/local/squid/etc/squid.conf is commented quite nicely.  Most options we'll just ignore and leave as is.  The options we do need to change and/or uncomment are:
    http_port 80             # listen on port 80
    emulate_httpd_log on     # use NCSA https style logfile
    http_access allow all    # this line replaces 'http_access deny all'
    httpd_accel_host www.example.com # hostname where Zope is running

  5. httpd_accel_port 8080    # port where Zope is running

  6. And last but not least, we need to tell Zope that it's running (from the user's point of view)  on port 80, not 8080.  For that we'll use Evan Simpson's SiteAccess product.  We add a SiteRoot object in Zope's root folder, and set BASE to http://www.example.com and the PATH to /.


That's it!   Now you can connect to http://www.example.com and Squid will serve up Zope pages for you.

For more info, visit:
http://www.squid-cache.org  - Squid homepage
http://www.zope.org/Members/anser/apache_zserver/- the same as (and the basis for) this Howto, only using Apache as the proxy
http://www.zope.org/Members/4am/SiteAccess