Varnish: Make cache dependent on X-Forwarded-Proto https

Viewed 5873

following situation: On the server is a apache and Varnish for caching. SSL is handled by an amazon load balancer. If the page is requested using https, the http header "X-Forwarded-Proto" is set to "https". The pages are sometimes different (e.g. links/images have to be fetched using https when using a secure connection)

How can I tell varnish that pages are different if the X-Forwarded-Proto header differs? As it is now, whatever is accessed first is cached and served for http and https!

3 Answers

The question and the answers are pretty old.

By now best practice is to utilize the Vary header (ironically, what the guy suggested who got his answer deleted in 2015).

You should avoid the hash_data() as much as possible.

Your backend should instead send Vary: X-Forwarded-Proto,Accept-Encoding. The Varnish server sees the header and does create seperate cache entries according to the protocol in the header set by the terminating instance.

Related