In NGINX, multiple location blocks can match a request URI. Which type of location block has the highest priority when matching a request?
Exact matches are checked before regex or prefix matches.
NGINX first checks for exact matches (=), then ^~ prefix matches, then regex matches (~ or ~*), and finally standard prefix matches.
Given this NGINX configuration snippet, what will be the response body when requesting /images/logo.png?
location = /images/logo.png {
return 200 'Exact match';
}
location ^~ /images/ {
return 200 'Prefix match';
}
location ~* \.(png|jpg)$ {
return 200 'Regex match';
}
location / {
return 200 'Default match';
}Check which location matches exactly the requested URI.
The = /images/logo.png location matches the URI exactly, so it is chosen before any prefix or regex matches.
Arrange the following NGINX location matching steps in the correct order of evaluation when a request arrives.
Exact matches are checked first, then prefix with ^~, then regex, then standard prefix.
NGINX first tries exact matches, then prefix matches with ^~, then regex matches, and finally standard prefix matches.
You have these location blocks:
location ^~ /api/ {
proxy_pass http://backend;
}
location ~ /api/v1/ {
proxy_pass http://v1-backend;
}Requests to /api/v1/users are always handled by http://backend. Why?
Check the priority order of ^~ vs regex locations.
Locations with ^~ prefix are checked before regex locations. So the /api/ prefix location matches first and stops further regex checks.
You want to serve static files under /static/ and API requests under /api/. You also have some regex locations for specific API versions. Which configuration approach is best for performance and clarity?
Think about how NGINX prioritizes location blocks and how to avoid unnecessary regex checks.
Using ^~ prefix locations for static and API paths avoids regex evaluation for those prefixes, improving performance. Regex locations are reserved for specific cases.