This example shows how to use 51Degrees' on-premise device detection and IP intelligence together in the same Nginx configuration.
This example shows how to use 51Degrees' on-premise device detection and IP intelligence together in the same Nginx configuration. This example is available in full on GitHub.
Both modules are loaded and each engine is given its own data file. The device detection matches use the request headers whilst the IP intelligence matches use the client IP address, or an IP address supplied in a query argument.
Make sure to include at least IsMobile for device detection and AsnName for IP intelligence for this to work. The AsnName property is available in the 51Degrees-IPIV4AsnIpiV41.ipi data file included in the ip-intelligence-data sub-module.
When running on a local machine the client IP address reported by Nginx is a loopback or private network address, which has no useful IP intelligence associated with it. The second IP intelligence match below therefore reads a real IP address from the client_ip query string argument via the $arg_client_ip variable, overriding the reported client IP address for that match. This is the mechanism used by the tests. In production the variable argument can be omitted, as in the first IP intelligence match below, so the client IP address is used directly.
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 two %%MODULE_PATH%% with the actual path.
- Remove the %%TEST_GLOBALS_HTTP%%.
- Update the %%FILE_PATH%% and %%FILE_PATH_IPI%% with the actual file paths.
- Replace the nginx.conf with this file or run Nginx with
-coption pointing to this file. - Create a static file
mixedin the Nginxdocument_root.
In a Linux environment, once Nginx has started, run the following command:
Expected output:
NOTE: All the lines above, this line and the end of comment block line after this line should be removed before using this example.
