I’m trying to setup Caddy v2 so it redirects from HTTP Port 80 from both my IPv4 and my IPv6 to my main domain to HTTPS.
My Caddyfile:
{
"experimental_http3": true
}
167.86.123.102, [2a02:c207:3004:1207:be:a:bad:babe] {
tls off
redir https://hnrk.io{uri} 301
}
hnrk.io, www.hnrk.io {
root * /etc/caddy/html
tls /etc/caddy/hnrk.io.crt /etc/caddy/hnrk.io.key
encode brotli zstd gzip
php_fastcgi unix//run/php/php7.3-fpm.sock
file_server /md browse
file_server
}
The converted file:
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"hnrk.io",
"www.hnrk.io"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "vars",
"root": "/etc/caddy/html"
},
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"encodings": {
"brotli": {},
"gzip": {},
"zstd": {}
},
"handler": "encode"
}
]
},
{
"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",
"rehandle": true,
"uri": "{http.matchers.file.relative}{http.request.uri.query_string}"
}
],
"match": [
{
"file": {
"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.3-fpm.sock"
}
]
}
],
"match": [
{
"path": [
"*.php"
]
}
]
},
{
"handle": [
{
"browse": {},
"handler": "file_server",
"hide": [
"Caddyfile"
]
}
],
"match": [
{
"path": [
"/md"
]
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"Caddyfile"
]
}
]
}
]
}
]
}
]
}
]
}
],
"experimental_http3": true
},
"srv1": {
"listen": [
":2015"
],
"routes": [
{
"match": [
{
"host": [
"167.86.123.102",
"2a02:c207:3004:1207:be:a:bad:babe"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "static_response",
"headers": {
"Location": [
"https://hnrk.io{http.request.uri}"
]
},
"status_code": 301
}
]
}
]
}
]
}
],
"automatic_https": {},
"experimental_http3": true
}
}
},
"tls": {
"certificates": {
"load_files": [
{
"certificate": "/etc/caddy/hnrk.io.crt",
"key": "/etc/caddy/hnrk.io.key"
}
]
},
"automation": {},
"session_tickets": {}
}
}
}
Now if I start Caddy v2 and request http://167.86.123.102, a blank HTTP 200 white page is displayed, same for the IPv6.
If I visit https://167.86.123.102, I get the following in Caddy’s logs:
2019/09/18 10:27:11 http: TLS handshake error from 62.157.168.126:29726: no certificate available for ''
2019/09/18 10:27:11 http: TLS handshake error from 62.157.168.126:29729: no certificate available for ''
In the JSON I see that the caddyfile adapter put the certificate and key paths into the second server block, whereas they are not supposed to be in there. Additionally "automatic_https": {}
should be disabled in the same block, because of tls off
.
Could it be a bug in the adapter or is my Caddyfile syntax wrong?
Thanks!