• About Us
  • Blog
  • Basket
  • Account
  • Sign In


Configuring the Varnish API

Before you start matching user agents, you may wish to configure the solution to use a different data set for example, or to use caching.

Init Settings - These settings are used in the vcl_init method and should only be set once.

Setting Default Description
fiftyonedegrees.start N/A Starts the 51Degrees module using the data set path provided. All other 51Degrees init options must be set before calling this.
fiftyonedegrees.set_cache 1000 Sets the size of the workset cache.
fiftyonedegrees.set_pool 20 Sets the size of the workset pool.
fiftyonedegrees.set_delimiter "," Sets the delimiter to separate values with.
fiftyonedegrees.set_properties All properties. Set the properties to initialise

Match Settings - These settings are valid in the vcl_recv and vcl_deliver methods, and any number can be set.

Setting Description
fiftyonedegrees.match_single Gets device properties using a User-Agent. Takes a User-Agent string and a comma separated list of properties to return.
fiftyonedegrees.match_all Gets device properties using multiple HTTP headers. Takes comma separated list of properties to return.

For full documentation, use

$ man vmod_fiftyonedegrees

Example Config

Below is an example config file showing how to load a Pattern data file, and set some device properties using the "match_single" and "match_all" directives. Some commonly used properties are set as request headers, some as a list and some as single headers. They are also set as response headers in the "vcl_deliver" method to make it possible to see how the matching works without having a full website set up.

Full Source File
# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.
# Default backend definition.  Set this to point to your content
# server.
vcl 4.0;
import fiftyonedegrees;

backend default {
	.host = "";
	.port = "80";

sub vcl_recv {
	set req.http.X-IsMobile = fiftyonedegrees.match_all("IsMobile");
	set req.http.X-BrowserName = fiftyonedegrees.match_all("BrowserName");
	set req.http.X-PlatformName = fiftyonedegrees.match_all("PlatformName");
	set req.http.X-Difference = fiftyonedegrees.match_all("Difference");
	set req.http.X-Method = fiftyonedegrees.match_all("Method");
	set req.http.X-Rank = fiftyonedegrees.match_all("Rank");
	set req.http.X-DeviceId = fiftyonedegrees.match_all("DeviceId");

sub vcl_deliver {
	set resp.http.X-IsMobile = fiftyonedegrees.match_all("IsMobile");
	set resp.http.X-BrowserName = fiftyonedegrees.match_single(req.http.user-agent, "BrowserName");
	set resp.http.X-PlatformName = fiftyonedegrees.match_single(req.http.user-agent, "PlatformName");
	set resp.http.X-Difference = fiftyonedegrees.match_all("Difference");
	set resp.http.X-Method = fiftyonedegrees.match_all("Method");
	set resp.http.X-Rank = fiftyonedegrees.match_all("Rank");
	set resp.http.X-ID = fiftyonedegrees.match_all("DeviceId");

sub vcl_init {
Full Source File