I came up with two approaches: one using a server-side language and the other using nginx config. Each of those solutions can be implemented in two ways: inject the CSS into the HTML, or generate a separate CSS stylesheet.
If you have a server-side language running, you can simply inject a <style> tag with the variables into the <head>.
By using the nginx config it means a server-side language doesn’t have to be set up. This approach can then be used for static sites.
Injecting content in nginx can be done with the ngx_http_sub_module. I believe it’s one of the default modules that nginx is compiled with.
I think there is probably an existing CSS file out there somewhere that contains a timestamp that could be used instead of having to modify the server config.