How does Varnish work? - Nothing super in-depth, but I think it’s important to understand how Varnish works at a high level to use it properly
Why host Varnish on the Edge with Fly? - Performance - not only do you get the performance benefits of Varnish, you also lower latency by serving it on the edge.
This one sounds amazing. I want to do a big “image service + caching” example with nginx, but it would be interesting to combine it with varnish as well.
This is a great outline - I’d add a few more things:
How to protect your backend so it is only available through Varnish, but yet retain the ability for you to access the backend to debug (via a custom access header)
How to monitor & “warm up” your Varnish install during the deploy process
I had a project where I used Varnish and due to the load (site was on TV, so immediate high load) I had to write a spider to warm up the cache a bit.
We’ve got this working locally in Docker (using a an Express app hosted on Fly as the backend), but when we try to run the Varnish image on Fly, we’re getting this error:
Running: docker-varnish-entrypoint varnishd -F -f /etc/varnish/default.vcl as root
Error: Could not resolve -T argument to address
Name or service not known
(-? gives usage)
reboot: Restarting system
It’s saying how to debug it - The -T flag on varnish opens a management console.
I’m assuming it can’t resolve the address of the backend server at that point. Try the default.vcf with and IP address first and see what the results are like.
@Gaurav I got the same error first, then I realized that Varnish runs on port 80 in the container. This means you need to update the internal_port in your fly.toml file:
...
[[services]]
internal_port = 80
...
Now it’s getting stuck at the building fs... step, but that might be another issue.
@ben Varnish is typically used for caching an entire web page as static HTML. Nginx usually sits behind it and serves dynamic content when Varnish doesn’t serve the static content.
I think this has something to do with the default varnish options, the -T control socket, and the Fly VM. I’m not sure if there’s a simpler way to start Varnish, but I’d try running it with minimal options. There should be a way to disable -T and override all its defaults by specifying a command like this: