1. The problem I’m having:
After using caddy adapt and trying to load the resulting JSON, I get an error. Command I’m running is:
caddy adapt sites/myexamplesite.com.Caddyfile --adapter caddyfile
This is a working Caddyfile. I want the JSON output so I can emulate it and generate it dynamically.
2. Error messages and/or full log output:
Error: adapting config using caddyfile: /mnt/c/Users/bowie/Documents/GitHub/caddyserver/sites/myexamplesite.com.json:37 - Error during parsing: Unexpected '{}' at end of line
the “zstd”: {} is line 37, context here:
"encodings": {
"gzip": {},
"zstd": {}
},
I tried adding a comma to the end of the line "zstd": {},
and the error changes to:
Error: adapting config using caddyfile: /mnt/c/Users/bowie/Documents/GitHub/caddyserver/sites/myexamplesite.com.json:126 - Error during parsing: Unexpected EOF
3. Caddy version:
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
I have tested this in two environments, one on Ubuntu on an AWS server using:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
as well as in WSL2 for Windows, using the same above method.
a. System environment:
WSL2 in Windows 11 and Ubuntu Ubuntu 22.04.2 LTS
b. Command:
caddy adapt sites/myexamplesite.com.Caddyfile --adapter caddyfile
caddy run
d. My complete Caddy config:
myexamplesite.com, www.myexamplesite.com {
encode zstd gzip
rewrite * /{http.request.host.labels.1}.{http.request.host.labels.0}{uri}
reverse_proxy * http://mybucket.s3-website-us-west-1.amazonaws.com {
header_up Host {upstream_hostport}
@error status 500 404
handle_response @error {
rewrite * /{http.request.host.labels.1}.{http.request.host.labels.0}/404.html
reverse_proxy * http://mybucket.s3-website-us-west-1.amazonaws.com {
@200 status 200
replace_status @200 404
header_up Host {upstream_hostport}
}
}
}
}