eZ Publish + lighttpd + static cache = success!

Author Message

Peter Putzer

Monday 27 August 2007 1:38:08 pm

If anyone else needs to set up eZ Publish with lighttpd and static cache, here's the configuration I'm using:

lighttpd.conf (snippet):

#
# Static cache (needs mod_magnet)
#
magnet.attract-physical-path-to = ( "/etc/lighttpd/static-cache.lua" )

static-cache.lua:

-- 
-- Static cache for eZ Publish
--

--
-- Requires Perl-comaptible regular expressions
--
require("rex_pcre")

uri_path = lighty.env["uri.path"]
static_cache_file = lighty.env["physical.doc-root"] .. "/static" .. uri_path .. "/index.html"

--
-- Do not rewrite some URLs
--
rewrite = 
        rex_pcre.match(uri_path, "\.(css|html?|pdf|js|png|gif|jpe?g|htc|jar|ico)$") == nil or 
        not(rex_pcre.match(uri_path, "^/content/download/.*$") == nil)
--
-- Never rewrite index.php
--
rewrite = rewrite and not(rex_pcre.match(uri_path, "^/index\.php"))

--
-- Some URLs can't be cached
--
cache = rewrite and (
                not(lighty.env["request.method"] == "POST") and
                lighty.env["uri.query"] == nil
                )

if cache then
        if not(nil == lighty.stat(static_cache_file)) then
                lighty.content = { { filename = static_cache_file } }
                lighty.header["Content-Type"] = "text/html"

                return 200
        else
                rewrite = true
        end
end

if (rewrite) then
        lighty.env["uri.path"] = "/index.php" .. lighty.env["uri.path"] 
        lighty.env["physical.rel-path"] = lighty.env["uri.path"]
        lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end

Accessible website starting from eZ publish 3.0 (currently: 4.1.0): http://pluspunkt.at

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.