nginx does not pick a location by file order. It first checks for an exact match with location = /path, and if one matches, stops. It then finds the longest matching prefix location; if that one is marked ^~, it stops there without evaluating regular expressions. Otherwise it evaluates regular expression locations in the order they appear in the file and uses the first that matches. If no regex matches, the remembered longest prefix is used.
The practical consequence is that a regex location anywhere in the file beats a longer prefix location, which is why a location ~ \.php$ block can hijack requests intended for a specific location /uploads/. Adding ^~ to the prefix location is the fix.
The exact-match form is worth using for hot single paths such as / and /healthz because it short-circuits everything else. Case-insensitive regex uses ~*. Nested locations are matched relative to the parent's prefix. Verify which location handled a request by adding a distinguishing header per location or by logging a variable set inside it, since nginx does not report the chosen location in its access log by default.