Caddy2 Cloudflare-DNS Implimentation Windows Native

  1. Caddy version (caddy version):
    Caddy v2

  2. How I run Caddy:
    administrative command prompt

a. System environment:
Windows 10 X64
WSL2 (aka. Windows Subsystem linux) Ubuntu 20.04

b. Command:

caddy start

d. My complete Caddyfile or JSON config:

    requests.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy2\log\ombi_access.log 
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files      
        }
            handle_errors C:\caddy\log\ombi_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }
      	reverse_proxy 127.0.0.1:5000
        tls {
            dns cloudflare {YR-58NwJN3ZdE42yww3qRQeEL5Y0D9c8CB9DrFFb}
        }
    }
    accounts.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy2\log\accounts_access.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files       
        }
            handle_errors C:\caddy\log\accounts_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }

        reverse_proxy 127.0.0.1:8056
        tls {
            dns cloudflare {YR-58NwJN3ZdE42yww3qRQeEL5Y0D9c8CB9DrFFb}
        }
    }
    stream.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy\log\jellyfin_access.log{
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files     
        }
            handle_errors C:\caddy\log\jellyfin_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }
    }    
        reverse_proxy 127.0.0.1:8096
        tls {
            dns cloudflare {YR-58NwJN3ZdE42yww3qRQeEL5Y0D9c8CB9DrFFb}
        }
    }
  1. The problem I’m having:
    I saw this post by bugs181
    Thanks for this! Somewhat new to Dockerfiles and have never used them before. I generally just follow self hosted tutorials and it’s all done via Docker Compose. What I don’t understand is that how does docker compose know to use the image from the Dockerfile?

Example:

Docker file:

FROM caddy:2.0.0-builder AS builder

RUN caddy-builder \
    github.com/caddy-dns/cloudflare

FROM caddy:2.0.0

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Compose file:

version: "3"

services:
  caddy:
    container_name: caddy
    build: .
    ports:
      - 80:80
      - 443:443
    volumes:
      - /home/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /home/docker/caddy/data:/data
      - /home/docker/caddy/config:/config

I’ve also read all documentation on

im sorry if im a bit of a noob. But im still very cconfused. Im trying to have my caddy v2 work with cloudflare dns.
i got the GitHub - caddy-dns/cloudflare: Caddy module: dns.providers.cloudflare download. But implementing it is rather difficult for me. I know theirs a way to do so. But everything i could find on a more in depth detail was either 404 on github from Feb 13, 2020 or didnt tell detail instructions.
Essentially im trying to build it to work natively in Windows 10. Ive already setup cloudflare to correctly work with v2. Meaning changing the api setup from v1 global key to cloudflares api key.
I can build using WSL ubuntu 20.04. So using linux on the same pc is not a problem. But i do want to make sure it works natively for Windows 10. Meaning when i build ill have to build likes so.

xcaddy build \
    --with github.com/caddy-dns/cloudflare
    --output GOOS=windows go build

i need to know what directory to build from, what directory the cloudflare-master folder goes in. What commands in detail are needed to build. Again most of the references were scattered and not very detail on what exactly to do. It would be really helpful to have like all in one tutorial on how to build using xcaddy from steps 1-10 or however many steps there are. If you give me the info. Ide be more than happy to write one out as well as make a video on youtube if you guys want.

  1. Links to relevant resources:
    Build from source — Caddy Documentation
    GitHub - caddy-dns/cloudflare: Caddy module: dns.providers.cloudflare
    Upgrading to Caddy 2 — Caddy Documentation
    Caddy2 cloudflare plugin - #8 by bugs181
    Caddy 2: wildcard + on demand certificates - #4 by jmstfv
    GitHub - caddyserver/xcaddy: Build Caddy with plugins
    How to use DNS provider modules in Caddy 2
    Cloudflare :: Let’s Encrypt client and ACME library written in Go.
    Thank you again ahead of time! its much appreciated

I think you just need to do this:

xcaddy build --with github.com/caddy-dns/cloudflare

By default it should output a new caddy.exe to your current directory, and GOOS will use the default which will already be windows if you run it on windows.

ive tried xcaddy which is installed on my wsl2 Ubuntu 20.04 but i get xcaddy is not a valid command. But ive triple checked that xcaddy is installed and a directory is there for it? Do you know if it has to be ran in a certain directory inside terminal?

In Linux/WSL, you need to give xcaddy executable permissions with chmod +x xcaddy and then if it’s in your current directory, prefix it with ./ to tell the shell you want to run it. If you move it to somewhere that’s in your PATH (like /usr/bin) then you don’t need to use ./

Should i chmod with root permissions. If not what permissions exactly should i give it. also if i were to move the xcaddy to /usr/bin then should i copy the directory or move the entire directory?

xcaddy is a single file static binary. You shouldn’t be dealing with any directories here.

okay now im getting confused. how would i install xcaddy correctly. i cant find the post on how i installed it but i know i installed it via caddys docs. Could you please explain to make sure i did correctly install xcaddy

not trying to be a neucence but i think you guys should update your documentation on xcaddy. This fixed my building of xcaddy

Thanks to mholt!

UPDATE:
Sorry again to bother but now i get this error when running xcaddy

techjunkiehosting@DevilsCoders-GamingRig:~/caddyoutput$ xcaddy build --with github.com/caddy-dns/cloudflare
2020/06/07 11:37:31 [INFO] Temporary folder: /tmp/buildenv_2020-06-07-1137.830871389
2020/06/07 11:37:31 [INFO] Writing main module: /tmp/buildenv_2020-06-07-1137.830871389/main.go
2020/06/07 11:37:31 [INFO] Initializing Go module
2020/06/07 11:37:31 [INFO] exec (timeout=10s): /usr/bin/go mod init caddy
go: creating new go.mod: module caddy
2020/06/07 11:37:33 [INFO] Pinning versions
2020/06/07 11:37:33 [INFO] exec (timeout=0s): /usr/bin/go get -d -v github.com/caddyserver/caddy/v2
2020/06/07 11:37:55 [INFO] exec (timeout=0s): /usr/bin/go get -d -v github.com/caddy-dns/cloudflare
go: finding github.com/caddy-dns/cloudflare latest
2020/06/07 11:38:01 [INFO] Build environment ready
2020/06/07 11:38:01 [INFO] Building Caddy
2020/06/07 11:38:01 [INFO] exec (timeout=0s): /usr/bin/go build -o /home/techjunkiehosting/caddyoutput/caddy -ldflags -w -s -trimpath
# github.com/caddyserver/certmagic
/home/techjunkiehosting/go/pkg/mod/github.com/caddyserver/certmagic@v0.10.12/handshake.go:201:18: hello.SupportsCertificate undefined (type *tls.ClientHelloInfo has no field or method SupportsCertificate)
2020/06/07 11:38:34 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-06-07-1137.830871389
2020/06/07 11:38:34 [FATAL] exit status 2

UPDATE #2: I uninstalled the go module because it was 1.13.8. I found a great tutorial to reinstall using How to Install Go on Ubuntu 18.04/20.04 · GolangCode
but edited it for the latest release so instead of

wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.14.2.linux-amd64.tar.gz

i used

wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.14.4.linux-amd64.tar.gz

this was actually the only one that would work on my WSL2 Ubunutu 20.04. It let me build the xcaddy package. the only issue is i cant figure out how to build it for windows because im using a Windows Subsystem Linux Distro. It thinks its actually a linux install. So i need to output it to windows. Could you please respond with the correct info to ouput it in Windows X64
Thank you!

i dont knwo where the output is going to this is the build log?

techjunkiehosting@DevilsCoders-GamingRig:~/caddy$ xcaddy build --with github.com/caddy-dns/cloudflare
2020/06/07 17:05:31 [INFO] Temporary folder: /tmp/buildenv_2020-06-07-1705.101982522
2020/06/07 17:05:31 [INFO] Writing main module: /tmp/buildenv_2020-06-07-1705.101982522/main.go
2020/06/07 17:05:31 [INFO] Initializing Go module
2020/06/07 17:05:31 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy
go: creating new go.mod: module caddy
2020/06/07 17:05:31 [INFO] Pinning versions
2020/06/07 17:05:31 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2
go: github.com/caddyserver/caddy/v2 upgrade => v2.0.0
2020/06/07 17:06:10 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddy-dns/cloudflare
go: github.com/caddy-dns/cloudflare upgrade => v0.0.0-20200522201047-5223567e8690
2020/06/07 17:06:16 [INFO] Build environment ready
2020/06/07 17:06:16 [INFO] Building Caddy
2020/06/07 17:06:16 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /home/techjunkiehosting/caddy/caddy -ldflags -w -s -trimpath
2020/06/07 17:07:35 [INFO] Build complete: caddy
2020/06/07 17:07:35 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-06-07-1705.101982522

./caddy version
v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

So what is the problem/question at this point? Looks like you built caddy successfully using xcaddy.

i built it succesfully but in my directories theres no exe for windows nor a linux caddy output. Im just wondering if you can tell me from the log if and where the file location is with my built caddy.exe

Well, as you can see from the log:

It ran ./caddy meaning Caddy in the current directory. The output from that command follows, so it worked.

So it’s in your ~/caddy directory, I guess.

but is that the exe file or a linux ubuntu file. Im trying to build it for windows 10 in WSL2 Ubuntu 20.04. So im not understanding if theres suppose to be an exe or is it outputting a linux file. because i need a exe file. I was told above that i dont have to run --output GOOS=windows go build command. Do i infact have to run xcaddy build --with github.com/caddy-dns/cloudflare --output GOOS=windows go build becuase its running WSL2 on a linux kernal technically?
btw everytime i try to run that exact command
xcaddy build --with github.com/caddy-dns/cloudflare --output GOOS=windows go build
i get this output
2020/06/07 19:18:47 [ERROR] missing flag; caddy version already set at go
heres my caddy directory

Where did you get --output GOOS=windows?

To cross compile, set the GOOS environment variable.

In bash, it’s like this:

$ GOOS=windows xcaddy build...

I don’t know how to do it on Windows.

I figured that because thats what the xcaddy github readme said below

btw this is the error i get now

2020/06/07 19:42:08 [FATAL] fork/exec ./caddy: permission denied

log of the compile

techjunkiehosting@DevilsCoders-GamingRig:~$  GOOS=windows xcaddy build --with github.com/caddy-dns/cloudflare
2020/06/07 19:36:28 [INFO] Temporary folder: /tmp/buildenv_2020-06-07-1936.186381958
2020/06/07 19:36:28 [INFO] Writing main module: /tmp/buildenv_2020-06-07-1936.186381958/main.go
2020/06/07 19:36:28 [INFO] Initializing Go module
2020/06/07 19:36:29 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init caddy
go: creating new go.mod: module caddy
2020/06/07 19:36:31 [INFO] Pinning versions
2020/06/07 19:36:31 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2
go: github.com/caddyserver/caddy/v2 upgrade => v2.0.0
2020/06/07 19:38:26 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddy-dns/cloudflare
go: github.com/caddy-dns/cloudflare upgrade => v0.0.0-20200522201047-5223567e8690
2020/06/07 19:38:44 [INFO] Build environment ready
2020/06/07 19:38:44 [INFO] Building Caddy
2020/06/07 19:38:44 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /home/techjunkiehosting/caddy -ldflags -w -s -trimpath
2020/06/07 19:42:08 [INFO] Build complete: caddy
2020/06/07 19:42:08 [INFO] Cleaning up temporary folder: /tmp/buildenv_2020-06-07-1936.186381958

./caddy version
2020/06/07 19:42:08 [FATAL] fork/exec ./caddy: permission denied

Update 1:
I might have fixed it. I needed to run

GOOS=windows xcaddy build --with github.com/caddy-dns/cloudflare

in the ~/caddy directory

Are you sure? Can you post a screenshot where it says that, because I don’t see that anywhere in the readme.

Setting environment variables has nothing to do with xcaddy or caddy – this is simply basic knowledge, “how to use your computer” kind of thing. There are too many systems for us to document how to use every single one.

As far as I can tell, the readme is correct.

I’m not sure. Make certain that the file is executable and that you’re in a folder where you have permission to execute programs.

im sorry for the late response i had to reboot my server. but i did succesfully compile the caddy.exe thank you so much! but now i am having the same problem as before when trying to run the caddy reload command.

2020/06/08 01:40:30.987 ←[34mINFO←[0m   using adjacent Caddyfile
reload: adapting config using caddyfile: parsing caddyfile tokens for 'log': Caddyfile:5 - Error during parsing: unrecognized subdirective: roll_size

any ideas?
btw heres my caddyfile im trying to reload

    requests.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy2\log\ombi_access.log 
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files      
        }
            handle_errors C:\caddy\log\ombi_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }
      	reverse_proxy 127.0.0.1:5000
        tls {
            dns cloudflare {cloudlare api key}
        }
    }
    accounts.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy2\log\accounts_access.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files       
        }
            handle_errors C:\caddy\log\accounts_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }

        reverse_proxy 127.0.0.1:8056
        tls {
            dns cloudflare {cloudflare api key}
        }
    }
    stream.movies4you.digital {
        encode gzip
        log {
            output file C:\caddy\log\jellyfin_access.log{
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files     
        }
            handle_errors C:\caddy\log\jellyfin_error.log {
            roll_size  150           # Set max size 150 MB
            roll_keep   7  # Keep log files for 7 days
            roll_keep_for  7 # Keep at most 2 log files
        }
    }    
        reverse_proxy 127.0.0.1:8096
        tls {
            dns cloudflare {cloudflare api key}
        }
    }

Do i still need the .bat to run the cloudflare api?
aka lego depreciated from here
https://go-acme.github.io/lego/dns/
ie.

 CLOUDFLARE_EMAIL=foo@bar.com \
CLOUDFLARE_API_KEY=b9841238feb177a84330febba8a83208921177bffe733 \
lego --dns cloudflare --domains www.example.com --email me@bar.com run

or is this the new update way of doing it

CLOUDFLARE_DNS_API_TOKEN=1234567890abcdefghijklmnopqrstuvwxyz \
lego --dns cloudflare --domains my.domain.com --email my@email.com run

btw heres the screenshot

Your syntax for the log directive is incorrect. Looks at the examples here:

handle_errors is not a replacement for errors in Caddy v1, that’s also incorrect usage. That directive defines a set of handlers that get executed if Caddy encounters an error (i.e. 502 if the proxy upsteam is not accessible). There’s no separation between access and error logging in Caddy v2.

For more info about how logging works:

okay i fixed those issues now im left with this error when running command: caddy reload caddyfile

c:\Caddy2>caddy run caddyfile
2020/06/08 06:06:42.442 ←[34mINFO←[0m   using adjacent Caddyfile
run: adapting config using caddyfile: Caddyfile:40 - Error during parsing: Unexpected EOF