The "location_match_finder" utility searches for a location that matches a given request including sublocation levels. Location search is carried out in accordance with the location block selection algorithm.
Testing was carried out on Nginx version 1.18.0
- Source code:
- location_match_finder.py - Script source code
- Test suites:
- nginx-config-example.conf - An example of the Nginx configuration file format
- uri.list - List of URIs for script testing
- Algorithms:
- location_selection_algorithm[LANG].jpg - Block schemes of the location match searching algorithm in different languages
To successfully run the "location_match_finder" utility, you must pass the required parameters:
- "--config-file=PATH" - Path to Nginx configuration file containing locations
- "--uri=URI" - Request URI in normalized form for which the search will be performed
To successfully parse the Nginx configuration file, all location directives must be converted to the following format:
- A line with a first-level directive must start with 4 spaces or 1 tab character
- A line with a second-level directive must start with 8 spaces or 2 tab characters
- A line with a third-level directive must start with 12 spaces or 3 tab characters
- All processed directives must be in a single file (include directive are not supported)
See example nginx-config-example.conf
Example of launching the Utility:
./location_finder.py config-file=tests/nginx-config-example.conf uri=/batchBoomer.xml
The result of the execution will be a hierarchical list of locations traversed during the search for a match
Level 1: /batch
Level 2: /batchBoom
Level 3: /batchBoomer
Level 3: ~ .xml$
And a message showing the final location where the request will be processed
Request [ /batchBoomer.xml ] will be processed by level 3 location [ ~ .xml$ ]