Use Varnish to serve static files directly from disk?
Batanun B
batanun at hotmail.com
Thu Jan 9 14:58:27 UTC 2025
Hi,
We use Varnish 6.0 (LTS), and we have the need to serve static files directly from disk. I would prefer not having to add another service (like nginx) and add it as a backend to varnish. If possible we would like to make Varnish serve the static files directly. We already do that for the html page for 500-errors, using this in vcl_backend_error:
synthetic(std.fileread("/etc/varnish/500.html"));
return (deliver);
Can we do something similar for regular content? Say that any path that starts with "/static-files/" gets "routed" to a file on disk under /some-files/. So a request for "/static-files/abc/123/x.txt" means it will serve the file "/some-files/abc/123/x.txt". And if the file doesn't exist we would like to serve a static html-file for the 404 error.
Is this is doable, and sensible? If so, is this documented somewhere?
For the time being, we don't really need to update the files, so maybe std.fileread is enough (if I understand it correctly it will only read one file once, then cache it forever)? But eventually people likely will want to update existing files, and without us having to restart Varnish. Would it make sense to start with std.fileread, or should we start with something else from the start? If the latter, is the "file" vmod the recommended way? The documentation mentions requiring the master branch of Varnish, which I'm not sure what that means. We use 6.0 (LTS) and we are not willing to move away from LTS.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20250109/ad74ad16/attachment.html>
More information about the varnish-misc
mailing list