Device detection
51Degrees
This page applies to:
- HAProxy Enterprise 1.7r2 and newer
The 51Degrees module provides device detection services using the 51Degrees database.
Install the 51Degrees module Jump to heading
- 
Go to the 51Degrees Downloads page to get the 51Degrees device detection data file. - For HAProxy Enterprise 3.0r1 and newer, use the V4 .hashdata file.
- For HAProxy Enterprise 2.9r1 and older, use the V3 .triedata file.
 
- For HAProxy Enterprise 3.0r1 and newer, use the V4 
- 
Copy the data file to your HAProxy Enterprise server. For example, /etc/hapee-3.2/51Degrees-LiteV4.1.hash.
- 
Install the 51Degrees module according to your platform. nixsudo apt-get install hapee-<VERSION>-lb-51dnixsudo apt-get install hapee-<VERSION>-lb-51dExample for HAProxy Enterprise 3.2r1: nixsudo apt-get install hapee-3.2r1-lb-51dnixsudo apt-get install hapee-3.2r1-lb-51dnixsudo yum install hapee-<VERSION>-lb-51dnixsudo yum install hapee-<VERSION>-lb-51dExample for HAProxy Enterprise 3.2r1: nixsudo yum install hapee-3.2r1-lb-51dnixsudo yum install hapee-3.2r1-lb-51dnixsudo zypper install hapee-<VERSION>-lb-51dnixsudo zypper install hapee-<VERSION>-lb-51dExample for HAProxy Enterprise 3.2r1: nixsudo zypper install hapee-3.2r1-lb-51dnixsudo zypper install hapee-3.2r1-lb-51dnixsudo pkg install hapee-<VERSION>-lb-51dnixsudo pkg install hapee-<VERSION>-lb-51dExample for HAProxy Enterprise 3.2r1: nixsudo pkg install hapee-3.2r1-lb-51dnixsudo pkg install hapee-3.2r1-lb-51d
- 
In the globalsection of your configuration, add the following lines. Change the51degrees-property-name-listdepending on the 51Degrees device properties you want to use. Note that some properties become available depending on your 51Degrees pricing tier.haproxyglobal...module-load hapee-lb-51d.so51degrees-data-file /etc/hapee-3.2/51Degrees-LiteV4.1.hash51degrees-property-name-list DeviceType IsMobile ScreenPixelsHeight ScreenPixelsWidthhaproxyglobal...module-load hapee-lb-51d.so51degrees-data-file /etc/hapee-3.2/51Degrees-LiteV4.1.hash51degrees-property-name-list DeviceType IsMobile ScreenPixelsHeight ScreenPixelsWidth
- 
Reload the configuration to apply the changes. nixsudo systemctl reload hapee-3.2-lbnixsudo systemctl reload hapee-3.2-lb
Use 51Degrees Jump to heading
After installing the module, use the following directives to manage the database.
51d.all Jump to heading
Use the fetch method 51d.all to perform a lookup in the database that returns the values of the specified properties. The function can be passed up to five property names. If a property name can’t be found, it returns the value NoData.
Syntaxtext
Syntaxtext
In this example, we create an HTTP request header that contains device information:
haproxy
haproxy
In the following example, we define an ACL named is_mobile and then use it when choosing a backend:
haproxy
haproxy
51d.single Jump to heading
Use the converter 51d.single to perform a lookup in the database that returns the values of the specified properties. It takes the User-Agent header as an input parameter. The function can be passed up to five property names. If a property name can’t be found, it returns the value NoData.
Syntaxtext
Syntaxtext
In this example, we create an HTTP request header that contains device information:
haproxy
haproxy
51d-set-property-vars Jump to heading
Available since:
- HAProxy Enterprise 3.2r1 and newer
Use the http-request directive to set variables based on property names specified with the 51degrees-property-name-list global option. If a property name can’t be found, it returns the value NoData.
Syntaxtext
Syntaxtext
<scope> must be set to proc, sess, txn, or req. <prefix> must be a string containing up to 64 characters of a-z, A-Z, 0-9, ., and _.
Each variable name is generated using the <scope>, the <prefix>, and the property name, separated by periods (.) like so:
text
text
For example, consider the following configuration:
haproxy
haproxy
A generated variable exampletext
A generated variable exampletext
Update the database during runtime Jump to heading
Use the 51Degrees Update module to keep the contents of the device detection database current. This allows you to keep multiple load balancers synced with the latest data.
- 
Install a web server of your choice and host the database file at a URL the load balancer can access. For example, host the file at http://192.168.0.1:8000/51Degrees-LiteV4.1.hash.
- 
Install the package hapee-3.2r1-lb-51d-update.nixsudo apt-get install hapee-<VERSION>-lb-51d-updatenixsudo apt-get install hapee-<VERSION>-lb-51d-updateExample for HAProxy Enterprise 3.2r1: nixsudo apt-get install hapee-3.2r1-lb-51d-updatenixsudo apt-get install hapee-3.2r1-lb-51d-updatenixsudo yum install hapee-<VERSION>-lb-51d-updatenixsudo yum install hapee-<VERSION>-lb-51d-updateExample for HAProxy Enterprise 3.2r1: nixsudo yum install hapee-3.2r1-lb-51d-updatenixsudo yum install hapee-3.2r1-lb-51d-updatenixsudo zypper install hapee-<VERSION>-lb-51d-updatenixsudo zypper install hapee-<VERSION>-lb-51d-updateExample for HAProxy Enterprise 3.2r1: nixsudo zypper install hapee-3.2r1-lb-51d-updatenixsudo zypper install hapee-3.2r1-lb-51d-updatenixsudo pkg install hapee-<VERSION>-lb-51d-updatenixsudo pkg install hapee-<VERSION>-lb-51d-updateExample for HAProxy Enterprise 3.2r1: nixsudo pkg install hapee-3.2r1-lb-51d-updatenixsudo pkg install hapee-3.2r1-lb-51d-update
- 
Add the following lines to the globalsection of your configuration:haproxyglobal...module-load hapee-lb-51d-update.so51degrees-update url http://192.168.0.1:8000/51Degrees-LiteV4.1.hash delay 24h loghaproxyglobal...module-load hapee-lb-51d-update.so51degrees-update url http://192.168.0.1:8000/51Degrees-LiteV4.1.hash delay 24h logBe sure to specify the port number where your file is hosted. The example above specifies port 8000.
With this configuration, HAProxy Enterprise downloads the database every 24 hours and prints a message in the logs when it succeeds or if it encounters errors during the update.
Runtime API Jump to heading
It is possible to manage the 51Degrees module via the HAProxy Runtime API.
51d-update force-update Jump to heading
Prerequisites
This command becomes available after you have installed both the 51Degrees and 51Degrees Update modules.
The 51Degrees Update module will update the database based on the interval you specified in the configuration. Use the 51d-update force-update command to force an immediate update of the 51Degrees database.
In this example, we force an update of the database:
nix
nix
outputtext
outputtext
51d-update status Jump to heading
Prerequisites
This command becomes available after you have installed both the 51Degrees and 51Degrees Update modules.
You can check the status of the update using the 51d-update status command. Note that while the update is processing, the status will show the progress:
nix
nix
outputtext
outputtext
51d-update show Jump to heading
Prerequisites
This command becomes available after you have installed both the 51Degrees and 51Degrees Update modules.
Use the 51d-update show command to display the configuration of the 51Degrees Update module. The output of this command includes information about each configured database file and its update status.
Below, we retrieve the status information for our configured databases:
nix
nix
outputtext
outputtext
Troubleshooting Jump to heading
This section covers troubleshooting steps.
Error reading 51Degrees data file Jump to heading
You get the following error during startup:
text
text
The data file you are trying to load isn’t compatible with the version of the HAProxy Enterprise 51Degrees module. For example, you tried to load a .trie data file, but the module expects a .hash data file.
- For HAProxy Enterprise 3.0r1 and newer, use the V4 .hashdata file.
- For HAProxy Enterprise 2.9r1 and older, use the V3 .triedata file.
Do you have any suggestions on how we can improve the content of this page?