I have a working varnish cache for my websites, with the undesired side effect that requests for a domain with http are cached with a certain url, and requests for https with another url. That way I end up with double objects in the cache, and I wanted to ask some best practices on how to optimize this behaviour.
In detail I have two vhosts within nginx for the same domain listening on port 80 and 443 each. Requests are proxy passed to varnish:
proxy_pass http://varnish:8101/VirtualHostBase/http/example.com:80/path/VirtualHostRoot/;
and
proxy_pass http://varnish:8101/VirtualHostBase/https/example.com:443/path/VirtualHostRoot/;
In varnish.vcl I check for the requesting host and set the right backend, since there are multiple ones.
if (req.http.host == "example.com") {
set req.backend = backend_0;
}
The backend is a Zope/Plone server. The pages are cached correctly in varnish, but I have an entry for /VirtualHostBase/http/example.com:80/path/VirtualHostRoot/logo.png and one for /VirtualHostBase/https/example.com:443/path/VirtualHostRoot/logo.png in my varnishlog (RxURL).
When Plone purges an entry, only the ssl version is purged, because every logged in user has to use https. The http entry remains until age invalidation.
Is it possible to combine http and https requests into one varnish object by rewriting urls? To save space and to do a successful purge. Maybe someone can give me a hint how to solve this!