Introduction
The project contains source code for the Varnish integration of 51Degrees' on-premise Device Detection engine.
Pre-requisites
- gcc
- autoconf
- automake
- libvarnishapi-dev
- Varnish source
For Ubuntu based distributions gcc can be found on apt, use
Install
Linux
For an existing Varnish deployment
Enhanced Device Data
By default the module will be built with the Lite Hash data file.
Amend src/Makefile.am
to use the name of your Premium or Enterprise data file.
Static Module
To install the module into an existing Varnish deployment,
first clone 51Degrees/device-detection-varnish repository with
This will also clone the dependent sub-module device-detection-cxx
and any of its' recursive sub-modules.
Move to the Varnish directory with
and install the module with (NOTE: if Varnish source was installed using the package manager, its' files will be located under /usr/include/varnish
directory rather than /usr/local/include/varnish
. The environment variable VARNISHSRC
will need to be set to point to this location for the installation to succeed).
Where --with-config
[optional] sets the version that will be built. release
and test
versions are identical, except that the test
version expose some additional functions to support the testing process. Only release
version is recommended for production. By default release
version is built.
When varnish is installed in a non standard directory, please set the value of environment variable VARNISHSRC
to point to where the varnish source resides before running the configure
(e.g. export VARNISHSRC=/usr/include/varnish
).
The location of where the module will be installed can also be customised by setting the environment variable VMOD_DIR
before running the configure
.
Then run the included tests with the following command. A test
version is required for this to succeed:
This will all pass if the local installation was successful.
Configure
Before start matching user agents, you may wish to configure the solution to use a different database for example.
Settings
General Settings
These settings should be set before calling fiftyonedegrees.start
.
set_performance_profile
(defaults toDEFAULT
). Set the performance profile.set_drift
(defaults to0
). Set the drift value.set_difference
(defaults to0
). Set the difference value.set_max_concurrency
(defaults is determined by the performance profile). Set the expected concurrent detection requests.set_allow_unmatched
(defaults isNO
). Set whether unmatched node should be allowed.set_use_performance_graph
(defaults is determined by the performance profile). Set whether the performance optimized graph should be used.set_use_predictive_graph
(defaults is determined by the performance profile). Set whether the predictive optimized graph should be used.set_delimiter
(defaults to','
). Sets the delimiter to separate values with.set_properties
(defaults to all properties). Sets the properties to initialise.
Usage
The easiest way to view full usage information is to run the command:
to display all the functions with examples.
The VCL File
An example configuration file is included in this repository. It shows how to add device information to HTTP headers.
Initialising the Resource Manager
In the init block is where you should set any settings and initialise the resource manager.
Matching
Matching can be done is two ways.
User-Agent match
To get properties using the device's User-Agent use:
Multiple HTTP header matches
To get properties from all the relevant HTTP headers from the device use:
Output Format
The value of the header is set to a comma separated list of values (comma delimited is the default behaviour, but the delimiter can be set explicitly with set_delimiter
), these are in the same order the properties are listed in the config file. So setting a header with the line:
will give a header named X-Device
with a value like Desktop,Firefox,Ubuntu
. Alternatively, headers can be set individually like:
giving three separate headers.
Example
Start Varnish using the example VCLs within the device-detection-varnish/examples/hash
directory with (NOTE: The data file path used by the start
API in the vcl_init
block will need to be updated before proceed):
Then, type start
to launch the worker process.
In a Linux environment, the headers can be viewed with the command:
which will give the following response: