V2 Caddyfile Migration - Unknown Directive

1. Caddy version (caddy version):

Latest docker build (but with cloudflare plugin)

2. How I run Caddy:

a. System environment:

Docker on unRAID v6.8.2

b. Command:

docker run -d --name='caddy' --net='bridge' -e 'CLOUDFLARE_AUTH_TOKEN'='#########' -p '80:80/tcp' -p '443:443/tcp' -v '/mnt/user/appdata/caddy/Caddyfile:/etc/Caddyfile' -v '/mnt/user/appdata/caddy':'/root/.caddy':'rw' 'abiosoft/caddy'

c. Service/unit/compose file:

https://hub.docker.com/r/abiosoft/caddy/dockerfile

d. My complete Caddyfile or JSON config:

stream.lightsong.cc:443 {
	reverse_proxy 192.168.1.20:32400 {
	}
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
		client auth {
			mode require_and_verify
			trusted_ca_cert_file origin-pull-ca.pem
		}
	}
}

dl.lightsong.cc {
	reverse_proxy 192.168.1.20:8112 {
	]
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
	}
}

radarr.lightsong.cc {
	reverse_proxy 192.168.1.20:7878 {
	}
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
	}
}

share.lightsong.cc {
	reverse_proxy 192.168.1.20:8686 {
	}
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
	}
}

sonarr.lightsong.cc {
	reverse_proxy 192.168.1.20:8989 {
	}
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
	}


stats.lightsong.cc {
	reverse_proxy 192.168.1.20:8181 {
	}
	tls amman.sood@gmail.com {
		dns cloudflare {env.CLOUDFLARE_AUTH_TOKEN}
	}
}

3. The problem I’m having:

I’m trying to upgrade my ancient deprecated Caddy install to v2, but no matter what I try, it immediately exits with “unknown directive”. I followed the V2 upgrade guide and I think I have all the syntax right, so I have no clue why it won’t run.

4. Error messages and/or full log output:

2020/09/11 01:49:10 /etc/Caddyfile:2 - Error during parsing: Unknown directive ‘reverse_proxy’

5. What I already tried:

I tried using reverse_proxy without the { } after it, no dice. I originally had “encode gzip” as the first line for each site definition, but that also gave me an unknown directive error.

6. Links to relevant resources:

Docker Image I use

Thanks in advance, been bashing my head into this for a few hours now, ended up going back to my V1 install for now.

Line 15 has typo:

BTW, you don’t need {} at the end of reverse_proxy if section is empty.

1 Like

Fixed the typo, same result. I tried reverse_proxy with and without the curly braces, no change.

Just for fun what happens if you remove the reverse_proxy lines altogether?

I did a quick validate test:

caddy version                                                                                                         1 ↔
v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

caddy validate -config Caddyfile-test                                                                                 1 ↔
2020/09/11 14:47:50.309 INFO    using provided configuration    {"config_file": "Caddyfile-test", "config_adapter": ""}
validate: adapting config using caddyfile: parsing caddyfile tokens for 'tls': Caddyfile-test:4 - Error during parsing: getting DNS provider module named 'cloudflare': module not registered: dns.providers.cloudflare

Test is on a Mac.

For that, make sure you build Caddy with all the plugins you need, in this case the cloudflare plugin. You can either do that from our website’s download page or with these instructions.

I built my own image and everything works now. Thanks!

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