Making decisions based on HTTP headers
One of the advantages of using Varnish is its versatility, allowing us to make decisions based on any header that comes in the web request.
While we previously saw how to block content by IP or by User-Agent it is equally easy to make decisions of any kind based on the value or mere existence of an HTTP header.
Changing the backend based on the header
Just as we explained here how to choose one backend or another based on a URL or host, it is equally simple to do it based on a header, for example, the geo_country_code.
Allowing traffic only to users with a specific header
This is especially useful when you need to restrict access to your site for any reason but don't want to protect it with Basic Authenticacion because that would prevent the site from being cached.
This mechanism is very useful, but you need your browser to include that HTTP header in each request for your navigation to work. To do this, we recommend installing the ModHeader Chrome extension.
Last updated