Configuring the Nginx API
Before you start matching user agents, you may wish to configure the solution to use a different database for example, or to use caching.
General Settings - These settings are valid in the main configuration block and should only be set once.
Setting | Default | Description |
---|---|---|
51D_filePath | '51Degrees.dat'/'51Degrees.trie' | Sets the location of the data file. |
51D_cache | 0 | Sets the size of the workset cache (Only relevant for pattern installation). |
Location Settings - These settings are valid in the location configuration block and any number can be set.
Setting | Description |
---|---|
51D_single | Gets device properties using a User-Agent. Takes the name the resultant header will be set as, and a comma separated list of properties to return. |
51D_all | Gets device properties using multiple HTTP headers. Takes the name the resultant header will be set as, and a comma separated list of properties to return. |
Example Config
Below is an example config file showing how to load a Patter data file from a non default location, set the cache size, and set some device properties using the "51D_single" and "51D_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 with the "add_header" directive to make it possible to see how the matching works without having a full website set up.
http {
## Set the data file for the 51Degrees module to use ##
51D_filePath ../data/51Degrees-LiteV3.2.dat;
## Enable caching with a cache size of 10000 ##
51D_cache 10000;
server {
listen 8888;
location / {
## Do a single User-Agent match for device information ##
51D_match_single x-device HardwareName,BrowserName,PlatformName;
## Do a multiple HTTP header match for IsMobile, IsTablet and IsSmartphone ##
51D_match_all x-mobile IsMobile;
51D_match_all x-tablet IsTablet;
51D_match_all x-smartphone IsSmartPhone;
## Do a multiple HTTP header match for match metrics ##
51D_match_all x-metrics DeviceId,Method,Difference,Rank;
## Add to response headers for easy viewing. ##
add_header x-device $http_x_device;
add_header x-mobile $http_x_mobile;
add_header x-tablet $http_x_tablet;
add_header x-smartphone $http_x_smartphone;
add_header x-metrics $http_x_metrics;
proxy_pass http://localhost/;
}
}
}