HAProxy Enterprise Documentation 2.0r1

51Degrees

The 51Degrees module provides device detection services using the 51Degrees database.

Install the 51Degrees module

  1. Log into your account at the 51Degrees website and download the enterprise database in Trie format. Copy the .trie file to your HAProxy Enterprise server (e.g. /etc/hapee-2.0/51Degrees-LiteV3.4.trie).

  2. Install the 51Degrees module according to your platform:

    $ # On Debian/Ubuntu
    $ sudo apt-get install hapee-2.0r1-lb-51d
    $ # On CentOS/RedHat/Oracle
    $ sudo yum install hapee-2.0r1-lb-51d
    $ # On SUSE
    $ sudo zypper install hapee-2.0r1-lb-51d
    $ # On FreeBSD
    $ sudo pkg install hapee-2.0r1-lb-51d
  3. In the global section of your configuration, add the following lines. Change the 51degrees-property-name-list depending on the properties you want to use:

    global
       module-path /opt/hapee-2.0r1/modules/
       module-load hapee-lb-51d.so
       51degrees-data-file /etc/hapee-2.0r1/51Degrees-LiteV3.4.trie
       51degrees-property-name-list DeviceType IsMobile IsTablet
  4. Reload the HAProxy Enterprise configuration to apply the changes.

Fetches and Converters

51d.all

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 and if a property name can't be found, the value "NoData" is returned.

Syntax

51d.all(<prop>[,<prop>*])

Example: Create an HTTP request header that contains device information

frontend www
   bind :80
   mode http
   http-request set-header X-DeviceInfo %[51d.all(DeviceType,IsMobile,IsTablet)]

Example: Define an ACL named is_mobile

frontend www
   bind :80
   mode http
   acl is_mobile 51d.all(IsMobile) "True"

51d.single

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 and if a property name can't be found, the value "NoData" is returned.

Syntax:

51d.single(<prop>[,<prop>*])

Example: Create an HTTP request header that contains device information

frontend www
   bind :80
   mode http
   http-request set-header X-DeviceInfo %[req.hdr(user-agent),51d.single(DeviceType,IsMobile,IsTablet)]

Update the database during runtime

Use the 51Degrees Update module to keep the contents of the device detection database current. This allows you to keep multiple instances of HAProxy Enterprise synced with the latest data.

  1. Install a Web server of your choice and host the database file at a URL where HAProxy Enterprise can access. For example, host the file at http://192.168.122.1/51Degrees-LiteV3.4.trie.

  2. Install the package hapee-2.0r1-lb-51d-update.

    $ # On Debian/Ubuntu
    $ sudo apt-get install hapee-2.0r1-lb-51d-update
    $ # On CentOS/RedHat/Oracle
    $ sudo yum install hapee-2.0r1-lb-51d-update
    $ # On SUSE
    $ sudo zypper install hapee-2.0r1-lb-51d-update
    $ # On FreeBSD
    $ sudo pkg install hapee-2.0r1-lb-51d-update
  3. Add the following lines to the global section of your configuration, where the URL hosts an updated version of the file:

    global
       # ... other global settings
       module-load hapee-lb-51d-update.so
       51degrees-update url http://192.168.122.1/51Degrees-LiteV3.4.trie delay 24h log

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.


Next up

DeviceAtlas