News

NGINX 1.31.5: "Predicate locations" route API traffic on any variable

NGINX 1.31.5 introduces variable-based location blocks: route traffic on headers, methods or JSON fields without external scripts.

UptimeMag editorial team · 8 September 2026 · 2 min read

NGINX 1.31.5: i "predicate locations" instradano il traffico API su qualsiasi variabile

NGINX released mainline version 1.31.5 on 2 September 2026, which changes one of the oldest configuration rules: a location block no longer needs to match a URI. Mainline 1.31.5 ships with a control API, predicate locations and the ngx_http_json_module.\n\nThe headline feature, called "predicate locations", allows a location block's matching to depend on any NGINX variable, not just the requested path. In 1.31.5, a location can also be defined by a variable preceded by the dollar sign: NGINX evaluates it at runtime and the location matches when the value is non-empty and not equal to "0"—any other value counts as a match. In practice, you cannot write a comparison directly like $arg_debug = 1 inside location: there is no new comparison syntax; the intended pattern is to calculate the result first (typically with map), then pass it to the location as a predicate.\n\nPredicate locations can be nested within each other and with traditional URI-based locations, allowing you to apply path-based routing first, then within that, logic based on headers, HTTP method or other fields.\n\nFor those managing APIs, the integration with the request body is the interesting part. The new client_body_early_read directive allows reading the body before NGINX selects the location; combined with the native JSON parser, it lets you extract a field via JSONPath (for example user.params.vip) and use it as a routing variable, without going through NJS for every routing decision. For more complex logic, NJS remains available, but only for targeted calculations: the actual routing goes back into locations.\n\nThis same release also debuts the Control API, a feature previously reserved for NGINX Plus and now open in the open-source core, exposing a REST interface to inspect running processes and configuration.\n\nBear in mind that 1.31.5 is an odd-numbered mainline branch: the stable even-numbered branch remains the safe choice for production, whilst the 1.31.x mainline branch is where experimental work lands. Those wanting to try the new directives in a test environment can check the official changelog on nginx.org and the documentation for ngx_http_core_module and ngx_http_json_module.\n

Written with the help of artificial intelligence and checked by the editors (EU AI Act, art. 50).