0
0
Nginxdevops~10 mins

Exact match (=) in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Exact match (=)
Request URL Received
Check location blocks
Is there a location with = prefix?
NoUse other location matching
Yes
Compare request URL exactly with location path
Exact match found?
NoTry other location blocks
Yes
Serve request using exact match location
END
Nginx checks if a location block with '=' prefix exactly matches the request URL path and serves it immediately if found.
Execution Sample
Nginx
location = /exact {
    return 200 'Exact match!';
}
This config serves requests exactly matching '/exact' with a 200 response and message.
Process Table
StepRequest URLLocation CheckedMatch TypeMatch ResultAction
1/exactlocation = /exactExact match (=)MatchServe with 200 'Exact match!'
2/exact/morelocation = /exactExact match (=)No matchTry other locations
3/exact/morelocation /exactPrefix matchMatchServe with prefix location
4/otherlocation = /exactExact match (=)No matchTry other locations
5/otherlocation /Prefix matchMatchServe with default location
💡 Exact match location serves only when request URL exactly equals location path.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
Request URLN/A/exact/exact/more/exact/more/other/other
Location MatchedNone= /exactNone/exactNone/
Key Moments - 2 Insights
Why does the exact match location not serve '/exact/more'?
Because the exact match (=) requires the request URL to be exactly '/exact'. '/exact/more' is longer, so it does not match the exact location (see execution_table rows 2 and 3).
What happens if no exact match location is found?
Nginx tries other location blocks like prefix matches until it finds one that matches (see execution_table rows 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what location serves the request URL '/exact'?
Alocation /exact
Blocation /
Clocation = /exact
DNo location serves it
💡 Hint
Check step 1 in the execution_table where '/exact' matches location = /exact exactly.
At which step does the request URL '/exact/more' get served by a prefix location?
AStep 3
BStep 2
CStep 1
DStep 5
💡 Hint
Look at step 3 in execution_table where '/exact/more' matches location /exact as prefix.
If the request URL is '/other', which location serves it according to the table?
Alocation = /exact
Blocation /
Clocation /exact
DNo location
💡 Hint
See steps 4 and 5 in execution_table where '/other' falls back to location /.
Concept Snapshot
Exact match (=) in nginx location blocks means the request URL must match the location path exactly.
If matched, nginx serves that location immediately.
If no exact match, nginx tries prefix or regex locations.
Use '=' prefix for exact match locations.
Example: location = /path { ... }
Full Transcript
When nginx receives a request, it checks location blocks to find the best match. If a location block uses the '=' prefix, nginx compares the request URL exactly to that location's path. If they match exactly, nginx serves the request using that location immediately. If not, nginx continues checking other locations like prefix or regex matches. For example, a location defined as 'location = /exact' will only serve requests to '/exact' and not '/exact/more'. This ensures precise control over which requests are handled by which location blocks.