-
Notifications
You must be signed in to change notification settings - Fork 36
Support for Caddy Server #558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the suggestions and for providing so much helpful detail. Caddy’s Server rewrites can be achieved via PHP as explained here. It performs surprisingly well, but if your Caddyfile config works then that’s great. I’ve added a small section to the docs linking back to this issue for anyone else interested in using server rewrites in Caddy (thank you!). |
I'd have thought the tags wouldn't matter as they'd be injected post the twig parsing stage, but I suppose your blitz stuff may be doing it's thing earlier than that? |
That’s probable, just needs some thorough testing. |
Just as an update, I've got what I thought should work done - but it isn't actually being spat out on the Caddy side of things. I've currently asked for help on their forums; https://caddy.community/t/httpinclude-not-seeming-to-be-parsed/21191 I'll update the thread here if I get things working. |
Sounds good. |
I now have this working, if you want to have a look and / or accept the changes, I've created a pull request. |
To add for clarity, this is the setup I have that now works with Blitz 4.9.1 I am using a .env (local)
.env (live)
config/blitz.php 'ssiTagFormat' => App::env('SERVER_TYPE') === 'caddy' ?
'<!--#caddy httpInclude "{uri}" -->' :
'<!--#include virtual="{uri}" -->', And for a minimal Caddyfile config with SSI support: website.url {
root * /websites/web-root
encode gzip zstd
file_server
templates {
between <!--#caddy -->
}
php_fastcgi unix//run/php/php8.1-fpm.sock
} Templates?The Caddy concept, and nothing to do with Craft's templates. Caddy has a "template" system of its own, which is how SSI is done here - it can also do more, like parse MarkDown. I am explicitly setting the Caddy A complete Caddyfile exampleCaddy itself transparently and automatically handles enforcing HTTPS, obtaining applying and renewing the certificates from LetsEncrypt, and serving HTTP3/QUIK without any configuration required. It's all done by default. A more complete Caddyfile example than above, with SSI support and Server Rewrites to avoid PHP altogether follows below. It also enforces the removal of a # Snippets
(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.website.url {
redir https://website.url{uri}
}
website.url {
root * /websites/web-root
encode gzip zstd
file_server
import blitzNoQueryString
templates {
between <!--#caddy -->
}
php_fastcgi unix//run/php/php8.1-fpm.sock
} |
Thanks! |
Hi, I want caddy only to bypass the blitzcache when following req. params are send:
How to change the following config?
|
That's more a question for Caddy than Craft I think - you're likely better asking here: https://caddy.community/c/help/5 (but if you find out, please do copy the answer here - sadly, I don't know) |
@r-anwar Blitz will never cache previews, so those should be bypassed automatically. Are you seeing otherwise? |
Blitz does not cache previews, thats corret but what I want is that blitz shouldnt get by passed when other arbitrary req. params are used. e.g. example.com?abc=def -> I want to deliver the cached version of that site. |
I would have guessed that commenting out |
Uh oh!
There was an error while loading. Please reload this page.
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
to
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
More complete / realistic Caddyfile example
The text was updated successfully, but these errors were encountered: