Skip to content

Support for Caddy Server #558

Description

@MattWilcox

UPDATE: Ben has addressed these issues as of 4.9.1, so if you want to see how to get Caddy Server configured correctly to support server re-writes (skip Craft/PHP when a Blitz file cache exists) and SSI too, read the final comment.


Two things; one would need work on the plugin itself and the other I think is more documentation.

SSI for Caddy

Caddy doesn't support "standard" SSI because it has a more powerful and "simpler" concept called Templates (their words, not mine). It looks like things could be made to work but the output of the SSI stuff Blitz does would need to change from

<!--#include virtual="/_includes?action=blitz%2Finclude%2Fcached&index=12345" -->

to

{{httpInclude "/_includes?action=blitz%2Finclude%2Fcached&index=12345"}}

when the server is Caddy.

The delimiters are configurable but I don't think that helps anything here.

Blitz server re-writes

You've got examples for nGinx and Apache, and I think the equivalent for Caddy is the following. It's certainly working for us, but it may not be quite as targeted as you want because this is only loading the Blitz file cache is there's no query at all (as opposed to a one called token).

Most simplistic solution Caddyfile config

some-website.com {
        root * /websites/REPO/web
        encode gzip zstd

        file_server

        @blitzCache {
                method GET
                not expression {query} != ''
        }
        route @blitzCache {
                try_files /cache/blitz/{host}{uri}/index.html {path} {path}/index.php?{query}
        }

        php_fastcgi unix//run/php/php8.1-fpm.sock
}

More complete / realistic Caddyfile example

# Snippets (see: https://caddyserver.com/docs/caddyfile/concepts)
(staticFileCache) {
        @static {
                file
                path *.ico *.css *.js *.gif *.jpg *.jpeg *.webp *.png *.svg *.woff2
        }
        header @static Cache-Control max-age=5184000
}

(blitzNoQueryString) {
        @blitzCache {
                method GET
                not expression {query} != ''
        }
        route @blitzCache {
                try_files /cache/blitz/{host}{uri}/index.html {path} {path}/index.php?{query}
        }
}

# Websites

an-old-domain.com,
www.some-website.com {
        redir https://some-website.com{uri}
}
some-website.com {
        root * /websites/REPO/web
        encode gzip zstd

        file_server
        import staticFileCache
        import blitzNoQueryString

        log {
                output file /websites/_logs/REPO.log
        }

        php_fastcgi unix//run/php/php8.1-fpm.sock
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions