Ubuntu Install with Custom Download

Note: I am 100% new to Caddy.

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

a. System environment:

Ubuntu 20 with systemd

b. Command:

sudo systemctl restart caddy

d. My complete Caddyfile or JSON config:

aspecthq.com {
	redir https://www.aspecthq.com{uri}
}
www.aspecthq.com {
    root * /var/www/aspecthq.com
    log {
        output file /var/log/caddy/aspecthq.com.access.log {
        	roll_size 3MiB
	        roll_keep 5
	        roll_keep_for 48h
        }
        format console
    }
    encode gzip zstd
    php_fastcgi unix//run/php/php8.1-fpm.sock
	file_server
	push   
}

3. The problem I’m having:

I have setup a brand new Ubuntu server and installed it via the normal apt install method. Everything was working until I turned Cloudflare back on. I discovered that I needed a custom Caddy build.

I was following the instructions here…

I named my custom download file caddy.cloudflare. I ran the following commands per the article above.

dpkg-divert --divert /usr/bin/caddy.default --rename /usr/bin/caddy
mv caddy.cloudflare /usr/bin/caddy.cloudflare
chown root:root /usr/bin/caddy.cloudflare
chmod +x /usr/bin/caddy.cloudflare
update-alternatives --install /usr/bin/caddy caddy /usr/bin/caddy.default 10
update-alternatives --install /usr/bin/caddy caddy /usr/bin/caddy.cloudflare 50

4. Error messages and/or full log output:

When I try to run caddy manually (when linked to caddy.cloudflare) I get the following output.

zsh: exec format error: caddy

When I use update-alternatives --config caddy to switch back to caddy.default caddy runs just fine.

5. What I already tried:

Detailed above.

6. Links to relevant resources:

None.

I think you just need to reload your shell after having made the changes. Your shell won’t be aware of the changes to PATH or whatever.

FYI, you don’t need to specify this, it’s already the default. Having it in your config though means that in a hypothetical situation where a TLS v1.4 is introduced, it wouldn’t be enabled for your server after an update because your config would prevent it. Best to just leave out that bit of config instead so that Caddy can control the defaults in future updates.

2 Likes

Thanks for the tip on the config. I will remove that.

I logged back in and everything seems to be the same. I also tried to compile my own version on my Mac using xcaddy.

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

When I test that binary on my Ubuntu server, I get the same exact error.

/usr/bin/caddy.cloudflare 
zsh: exec format error: /usr/bin/caddy.cloudflare

I am not very familiar with Go. Do I need to compile the version on my Ubuntu server?

Exec format error means you’re running a binary not built for your platform. make sure it’s compiled for the OS and arch of your system, but you don’t have to compile it on that same system (cross compiling go is easy and our docs explain how). Or just use our download page to get what you need.

Oh my goodness! I totally missed the platform dropdown on the download page. What a n00b…

1 Like

And it works when I get the correct download!

1 Like

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