0
0
Nginxdevops~5 mins

Location blocks in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a location block in nginx?
A location block defines how nginx should respond to requests for specific URLs or URL patterns.
Click to reveal answer
beginner
How do you write a simple location block to match the URL /images/?
Use location /images/ { ... } to match all requests starting with /images/.
Click to reveal answer
intermediate
What is the difference between location = /path and location /path?
location = /path matches the exact URL /path only, while location /path matches any URL starting with /path.
Click to reveal answer
intermediate
What does the ^~ modifier do in a location block?
The ^~ modifier tells nginx to stop searching if this prefix match is found and use this block immediately.
Click to reveal answer
advanced
How does nginx choose which location block to use when multiple match?
Nginx first looks for exact matches, then prefix matches with ^~, then regex matches, and finally the longest prefix match.
Click to reveal answer
Which location block matches only the exact URL /about?
Alocation /about { ... }
Blocation = /about { ... }
Clocation ^~ /about { ... }
Dlocation ~ /about { ... }
What does the ^~ modifier do in a location block?
AMatches regex patterns
BIgnores this location block
CMatches exact URL only
DStops searching on prefix match
Which location block matches URLs starting with /api/?
Alocation = /api/ { ... }
Blocation ~ /api/ { ... }
Clocation /api/ { ... }
Dlocation ^~ /api/ { ... }
If multiple location blocks match, which one does nginx prefer first?
AExact match
BRegex match
CLongest prefix match
DFirst defined block
How do you define a location block that matches URLs using a regex?
Alocation ~ /pattern/ { ... }
Blocation /regex/ { ... }
Clocation = /regex/ { ... }
Dlocation ^~ /pattern/ { ... }
Explain how nginx chooses which location block to use when multiple blocks match a request URL.
Think about the order nginx checks location blocks.
You got /4 concepts.
    Describe the difference between prefix matches and regex matches in nginx location blocks.
    Consider how nginx processes URL patterns.
    You got /4 concepts.