Although I’m using this for local sites using Caddy’'s local_certs
and tls internal
for https
, it could be adapted for a live server with other certificates.
This Caddyfile has been tested on my Mac, with PHP and Caddy installed via brew with Kirby v2 installed via the old Kirby CLI and Kirby v3 via Composer.
- MacOS Catalina 10.15.4
- PHP 7.4.5
- Caddy v2.0.0
- Kirby K2 latest and Kirby 3.3.5
It is based on snippets to allow some flexibility, Modern CMS’s like Kirby v3 don’t really need too much, but Kirby v2 proved to be a bit more tricksy.
Please let me know if you see anything amiss and I will try and correct it.
My thanks to francislavoie & Whitestrake for all their help!
# Caddy v2 file for Kirby 2 & Kirby 3 local sites
# v0.1.0
# 2020/05/10
#=====================
# Global Block
{
email youremail@domain.tld
local_certs
}
# Snippets
# Common server snippet use 'import common'
(common) {
encode gzip
php_fastcgi localhost:9000
tls internal
file_server
header * {
# You may want some other header options...
X-Frame-Options "DENY"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
}
}
#---------------------
# Kirby 2 & 3 common snippet use 'import kirby'
(kirby) {
@blocked {
path *.txt *.md *.mdown /site/* /kirby/*
}
redir @blocked /
}
#---------------------
# Kirby 2 snippet use 'import kirby2'
(kirby2) {
# /panel files
handle /panel* {
try_files {path} {path}/ /panel/index.php?{uri}&{query}
}
@notPanel {
not path /panel*
}
handle @notPanel {
try_files {path}/ /index.php?&{query}
}
}
#---------------------
# Cachebuster rewrite style.123213.css -> style.css 'import cachebuster'
(cachebuster) {
@cachedFiles {
not file
path_regexp cached ~*(.+)\.(?:\d+)\.(js|css|jpg|svg|png)
}
rewrite @cachedFiles {http.regexp.cached.1}.{http.regexp.cached.2}
}
#=====================
# Virtual Hosts - domains need to be added to your hosts file
kirby2site.test:443 {
root * /PATH_TO_SITE/kirby2site
import common
import kirby
import kirby2
}
kirby3site.test:443 {
root * /PATH_TO_SITE/kirby3site
import common
import kirby
}
kirby2cachebustersite.test:443 {
root * /PATH_TO_SITE/kirby2cachebustersite
import common
import cachebuster
import kirby
import kirby2
}