Good question, I think I understand it, but I’m not sure I know the answer, to be perfectly honest with you.
I tried to simplify the Caddyfile to produce a simpler JSON.
Caddyfile :
voiretmanger.fr {
@cache {
not {
header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
method POST
expression {query} != ''
}
}
route @cache {
header cache file
try_files /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
}
header cache wp
php_fastcgi unix//run/php/php7.4-fpm-caddy.sock
}
JSON :
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"voiretmanger.fr"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "headers",
"response": {
"set": {
"Cache": [
"wp"
]
}
}
}
]
},
{
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "headers",
"response": {
"set": {
"Cache": [
"file"
]
}
}
}
]
},
{
"group": "group0",
"handle": [
{
"handler": "rewrite",
"uri": "{http.matchers.file.relative}"
}
],
"match": [
{
"file": {
"try_files": [
"/wp-content/cache/cache-enabler/{http.request.host}{http.request.uri}/index.html",
"{http.request.uri.path}"
]
}
}
]
},
{
"group": "group0",
"handle": [
{
"handler": "rewrite",
"uri": "{http.matchers.file.relative}?{http.request.uri.query}"
}
],
"match": [
{
"file": {
"try_files": [
"{http.request.uri.path}/index.php"
]
}
}
]
},
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"{http.request.uri.path}/"
]
},
"status_code": 308
}
],
"match": [
{
"file": {
"try_files": [
"{http.request.uri.path}/index.php"
]
},
"not": [
{
"path": [
"*/"
]
}
]
}
]
},
{
"handle": [
{
"handler": "rewrite",
"uri": "{http.matchers.file.relative}"
}
],
"match": [
{
"file": {
"split_path": [
".php"
],
"try_files": [
"{http.request.uri.path}",
"{http.request.uri.path}/index.php",
"index.php"
]
}
}
]
},
{
"handle": [
{
"handler": "reverse_proxy",
"transport": {
"protocol": "fastcgi",
"split_path": [
".php"
]
},
"upstreams": [
{
"dial": "unix//run/php/php7.4-fpm-caddy.sock"
}
]
}
],
"match": [
{
"path": [
"*.php"
]
}
]
}
]
}
],
"match": [
{
"not": [
{
"expression": "{http.request.uri.query} != ''",
"header_regexp": {
"Cookie": {
"pattern": "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
}
},
"method": [
"POST"
],
"path_regexp": {
"pattern": "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
}
}
]
}
]
},
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"{http.request.uri.path}/"
]
},
"status_code": 308
}
],
"match": [
{
"file": {
"try_files": [
"{http.request.uri.path}/index.php"
]
},
"not": [
{
"path": [
"*/"
]
}
]
}
]
},
{
"handle": [
{
"handler": "rewrite",
"uri": "{http.matchers.file.relative}"
}
],
"match": [
{
"file": {
"split_path": [
".php"
],
"try_files": [
"{http.request.uri.path}",
"{http.request.uri.path}/index.php",
"index.php"
]
}
}
]
},
{
"handle": [
{
"handler": "reverse_proxy",
"transport": {
"protocol": "fastcgi",
"split_path": [
".php"
]
},
"upstreams": [
{
"dial": "unix//run/php/php7.4-fpm-caddy.sock"
}
]
}
],
"match": [
{
"path": [
"*.php"
]
}
]
}
]
}
],
"terminal": true
}
]
}
}
}
}
}
It produces a lot of indentation and I don’t know the internals of Caddy 2 enough to see if there’s an obvious error here.
At first glance, it seems OK and I would guess there is a bug, but maybe I’m misunderstanding something ?