Has anyone paired Varnish with Caddy?

Hey everyone,
I’ve been looking into ways to improve website performance on one of the servers I manage & thought about trying out Varnish cache for the first time. Naturally no tutorials exist for this as yet (that I can find anyway. Just wanted to find out if anyone has given this a shot.
I’m looking to implement this in front of a Wordpress site on a 512 Digital Ocean droplet & I haven’t used Varnish before if that helps anyone wishing to give some advice/pointers.

No, but
I’ve done it with nginx
varnish is “just” a caching proxy.
So caddy proxy configuration should work.
However when I used varnish I had problems with streaming mp3 files.
Varnish 3 worked more reliably for most types of content where Varnish 4 would give me more trouble and in the end I would abandon both.

That said, I have 1 server that serves multiple PHP sites and sits on front of the chain.

There isn’t really a whole lot of configuration examples for varnish and asking for support seems to be private entities which require some kind of compensation which is why I probably won’t be using it any more.

Default values for V3 worked rather well and what I could piece together from random internet posts.

What a coincidence, I was also going to try Varnish. I gave it a shot but failed at configuring Varnish, so I rolled back everything. But basically I proxied from Caddy (port 80/443) to Varnish, and then Varnish to Caddy (website on a different port), and Caddy to php-fpm. Let me know if you manage to setup it, otherwise I will probably try it myself this weekend again :slight_smile:

@Nixtren @dalu Thanks for the responses guys. I’ll be looking at giving it a shot over the weekend. I’ll report back on my experience.

Got Caddy + Varnish running, here’s how I did it:

example.com {
    proxy / localhost:6081 { # Proxy to Varnish
                header_upstream Host "localhost" # Won't work with another value or transparent preset
                header_upstream X-Real-IP {remote}
                header_upstream X-Forwarded-For {remote}
                header_upstream X-Forwarded-Proto {scheme}
        }
}
localhost:8060 { # Varnish will access this
        tls off
        # Everything about your website goes here, fastcgi and etc
}

And setup Varnish following this tutorial (works for Debian and Debian-based distros):

Use these configurations:

DAEMON_OPTS="-a :6081 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,128m"

On default.vcl:

backend default {
    .host = "localhost";
    .port = "8060";
}

Enjoy people :slight_smile:

3 Likes

Be careful using this with Caddy 0.9.2 (0.9.1 is fine), requests started mixing from what I’ve seen. See my comment at:
https://github.com/mholt/caddy/issues/1056#issuecomment-248778919

I will open a proper issue on GitHub this weekend.

Edit: Didn’t have time to debug it further & open the issue

I did the same config for Caddy V2 with code adaptation but it does not work:

viktorli.hopto.org {
        reverse_proxy http://192.168.200.184:6081 {
                header_up Host "localhost"
                header_up X-Real-IP {remote_host}
                header_up X-Forwarded-For {remote_host}
                header_up X-Forwarded-Proto {scheme}
        }
}

192.168.200.184:80 {
        root * /var/www/html
        php_fastcgi wordpress:9000
        file_server
}

/etc/varnish/default.vcl:

backend default {
    .host = "192.168.200.184";
    .port = "80";
}

When trying to connect to https://viktorli.hopto.org I am getting thrown to https://localhost/