\r\n

51Degrees Device Detection Nginx  4.3

A device detection module for Nginx

hash/matchMetrics.conf

This example shows how to obtain further metrics for 51Degrees' on-premise device detection in Nginx. The available metris are Drift, Difference, Method, UserAgents, DeviceId and MatchedNodes. This example is available in full on GitHub.

This example requires a local data file. Free data files can be acquired by pulling the submodules under this repository or from the device-detection-data GitHub repository.

Make sure to include at least IsMobile property for this to work.

Before using the example, update the followings:

  • Remove this 'how to' guide block.
  • Update the %%DAEMON_MODE%% to 'on' or 'off'.
  • Remove the %%TEST_GLOBALS%%.
  • Update the %%MODULE_PATH%% with the actual path.
  • Remove the %%TEST_GLOBALS_HTTP%%.
  • Update the %%FILE_PATH%% with the actual file path.
  • Replace the nginx.conf with this file or run Nginx with -c option pointing to this file.
  • Create a static file metrics in the Nginx document_root.

In a Linux environment, once Nginx has started, run the following command:

$ curl localhost:8080/metrics -I -A "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53"

Expected output:

HTTP/1.1 200 OK
...
x-metrics: 0,0,PERFORMANCE,18
x-user-agents: _________.0 (iPhone_______Phone ___7_1 like ____OS X_______WebK__________2 (KHTML,______Gecko_ Ver_________Mobile______7 Safari________
x-device-id: 12280-24384-24305-0
...

NOTE: All the lines above, this line and the end of comment block line after this line should be removed before using this example.

## Update DAEMON_MODE to 'on' or 'off' before running with Nginx ##
daemon %%DAEMON_MODE%%;
worker_processes 4;
## The following line is only for testing. Remove before running ##
## with Nginx ##
%%TEST_GLOBALS%%
## Update MODULE_PATH before running with Nginx ##
load_module %%MODULE_PATH%%modules/ngx_http_51D_module.so;
events {
worker_connections 1024;
}
# // Snippet Start
http {
## The following line is only for testing. Remove before ##
## running with Nginx ##
%%TEST_GLOBALS_HTTP%%
## Set the data file for the 51Degrees module to use ##
## Update the FILE_PATH before running with Nginx ##
51D_file_path %%FILE_PATH%%;
51D_drift 1;
51D_difference 1;
51D_use_performance_graph on;
51D_use_predictive_graph off;
server {
listen 127.0.0.1:8080;
server_name localhost;
location /metrics {
## Get the metrics for the match using single User-Agent ##
51D_match_single x-metrics Drift,Difference,Method,MatchedNodes;
## Get the matched user agent string ##
51D_match_single x-user-agents UserAgents;
## Get the matched device ID ##
51D_match_single x-device-id DeviceId;
## Add to response headers for easy viewing. ##
add_header x-metrics $http_x_metrics;
add_header x-user-agents $http_x_user_agents;
add_header x-device-id $http_x_device_id;
}
}
}
# // Snippet End