Convert V1 caddyfiles to v2?

1. Caddy version (caddy version):

docker: abisoft/caddy:latest

2. How I run Caddy:

multiple sites loaded from multiple caddyfiles via
import /opt/docker/caddy/sites/*.conf

a. System environment:

Docker:

b. Command:

caddy --conf /opt/caddy/Caddyfile --log stdout --agree=$ACME_AGREE

c. Service/unit/compose file:

Docker, 

d. My complete Caddyfile or JSON config:

main caddyfile

import /opt/caddy/sites/*conf

anything with a comment, indicates a seperate file

## basic redicts
http://codeexample.com {
        redir https://example.com
}

http://(server IP addr) {
	redir https://example.com
}

# file server
https://cdn.example.com {

        tls /opt/caddy/cert/pub /opt/caddy/cert/priv

        root /opt/fileserver/
        log /opt/caddy/log/cdn.log
	errors /opt/caddy/log/cdn.err

        browse /

	basicauth /games/	user password

	markdown /
}

# code-server
https://code.example.com {

        tls /opt/caddy/cert/pub /opt/caddy/cert/priv        

        basicauth / user password

        proxy / 192.168.0.115:8080 {
		websocket
		transparent
        }

        log /opt/caddy/log/vscode.log
	errors /opt/caddy/log/vscode.log
        proxy /http 192.168.0.115:8081 { 
	        transparent
        }
}

# gitea
https://git.example.com {
        tls /opt/caddy/cert/pub /opt/caddy/cert/priv
#	redir / https://github.com/Merith-TK

	log /opt/caddy/log/git.log
	errors /opt/caddy/log/git.log.err

	proxy / 172.17.0.3:3000 {
		websocket
		transparent
	}
}

# mailcow
https://mail.example.com {
        tls /opt/caddy/cert/pub /opt/caddy/cert/priv

        log /opt/caddy/log/mail.log
        errors /opt/caddy/log/mail.err

	proxy / 127.0.0.1:8084	 {
		websocket
		transparent
	}
}

# nextcloud
https://next.example.com {
        tls /opt/caddy/cert/pub /opt/caddy/cert/priv

        root /opt/nextcloud/
        log /opt/caddy/log/next.log
        errors /opt/caddy/log/next.err

	proxy / 192.168.0.101:8081 {
		websocket
		transparent
	}
}

http://next.example.com {
  redir https://{host}{uri}
}

# main website
https://example.com, https://www.example.com {

        tls /opt/caddy/cert/pub /opt/caddy/cert/priv

        root /opt/caddy/websites/www
        index index.html
        log /opt/caddy/log/www.log
	errors /opt/caddy/log/www.err
}

3. The problem I’m having:

I have no clue in converting v1 configs to v2,
I had to convert a config on my phone and converting something as simple as

http://localhost:8080 {
browse /sdcard/WWW/
index .html
root ./
}

was a nightmare for me

4. Error messages and/or full log output:

No errors,

5. What I already tried:

I have no clue what im doing at all

6. Links to relevant resources:

Thankfully, we have an upgrade guide that will make it a lot less nightmare-ish! :slight_smile: Upgrading to Caddy 2 — Caddy Documentation

I would recommend just starting with a clean slate for v2. Much easier than trying to do a 1:1 conversion.

as you can see, i have alot of configs (definately not the most, but alot)
this will be quite difficult for me as im used to one format.

if caddyv2 couldve supported v1 configs by having a flag like config 1 or config 2 for the caddyversion, that wouldve been nice

There is no directive for the errors /opt/caddy/log/cdn.err config from v1 that i can find for v2,
this is kinda important so i can check who accessed what separately from what errors caddy throws out

edit:
Also how do i reverse proxy websockets with a transperant proxy? are those configs the same? or have they been relabeled like litterally 80% of everything else

Unfortunately, Caddy v2’s complete, from-the-ground-up rewrite prevents any kind of config logic from v1 from being remotely applicable to v2. Any kind of backwards compatibility would have to take the form of an interpreting/translating layer converting v1 Caddyfile to v2 config.

In fact, Caddy’s native config language is JSON. The v2 Caddyfile isn’t even directly applicable to Caddy v2 configuration! It has to be adapted first. But even so, some of the ways v1 did things - and many of the assumptions about how that configuration effected things - are done totally differently under the hood now and it’d be dangerous to give the impression that a literal translation will always achieve the same result in v2.

I’d suggest that if you don’t have a log parser that can handle filtering, you can do a quick-and-dirty grep for something like "status": 4 or "status": 5 which should limit the results to error responses.

Alternatively, you can go down to the JSON to configure log outputs and including/excluding whatever arbitrary content you might like: JSON Config Structure - Caddy Documentation

Reverse proxy transparency, and websockets, are now completely automatic and require no extra configuration.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.