Skip to content
iD-SIGN
Contact us

NGINX and the Processing Priority of location Directives

In an NGINX domain configuration you can have several location directives whose settings overlap. Here is the order in which they are evaluated

1 min readpublished 11/2020

Fortunately, the order in which the individual directives are evaluated is very simple and logical:

  1. = (exact match), e.g. location = /path – if the URI matches exactly, the search ends.
  2. The longest matching prefix, e.g. location /path or location ^~ /path – NGINX remembers it. If it has the ^~ modifier, the search ends and regular expressions are not checked. A shorter prefix with ^~ stops nothing.
  3. ~ and ~* (case-sensitive and case-insensitive regular expressions), e.g. location ~* \.(jpg|png|bmp)$ – they are checked in the order in which they appear in the configuration, and the first match wins.
  4. If no regular expression matches, the longest prefix from step 2 is used.

You can try the order in an online tester for location directives.

Tags Servers, Nginx

Share LinkedIn Facebook

Need more than an article?

A few sentences about what you are dealing with are enough.