Oh if your map still has :80
, then it needs to be :443
, cause HTTPS is over port 443.
Re route
, there must be something else going on in your config, cause there’s no reason for that to be the case.
Also to make reading the caddy adapt --pretty
output less annoying, you can enter tabs -2
to set the tab size to 2 spaces for your current shell session.
If I write a Caddyfile like this:
*.udance.com.au {
map {labels.3} {backend} {online} {mtls} {phpmyadmin} {
# HOSTNAME BACKEND ONLINE mTLS PHPMYADMIN #COMMENT
#---------------------------------------------------------------
# Jails
test 10.1.1.50:80 yes yes yes # test.udance.com.au
}
# Secure backend communication
@mtls expression `{mtls} == "yes"`
handle @mtls {
reverse_proxy {backend}
}
# Unsecured backend communication
@nomtls expression `{mtls} == "no"`
handle @nomtls {
reverse_proxy {backend}
}
}
Then adapt it, I get this, which all makes sense (subroutes in the right place etc)
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"*.udance.com.au"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"destinations": [
"{backend}",
"{online}",
"{mtls}",
"{phpmyadmin}"
],
"handler": "map",
"mappings": [
{
"input": "test",
"outputs": [
"10.1.1.50:80",
"yes",
"yes",
"yes"
]
}
],
"source": "{http.request.host.labels.3}"
}
]
},
{
"group": "group2",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "{backend}"
}
]
}
]
}
]
}
],
"match": [
{
"expression": "{mtls} == \"yes\""
}
]
},
{
"group": "group2",
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "{backend}"
}
]
}
]
}
]
}
],
"match": [
{
"expression": "{mtls} == \"no\""
}
]
}
]
}
],
"terminal": true
}
]
}
}
}
}
}
(Also you could pipe the output into jq
, like caddy adapt | jq
which will syntax highlight it and format it. See jq )