Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the order of location matching priority in nginx?
nginx matches locations in this order: 1) Exact match (=), 2) Longest prefix match, 3) Regular expression (~ or ~*), 4) If no match, default location (/).
Click to reveal answer
beginner
What does the '=' symbol mean in an nginx location block?
The '=' symbol means an exact match. nginx will serve this location only if the request URI exactly matches the location path.
Click to reveal answer
intermediate
How does nginx handle multiple prefix locations that match a request URI?
nginx chooses the longest matching prefix location among those without '=' or regex modifiers.
Click to reveal answer
intermediate
What is the difference between '~' and '~*' in nginx location blocks?
'~' means case-sensitive regular expression match, while '~*' means case-insensitive regular expression match.
Click to reveal answer
beginner
What happens if no location matches a request URI in nginx?
nginx uses the default location '/' if no other location matches the request URI.
Click to reveal answer
Which location block does nginx check first when matching a request URI?
ARegular expression (~ or ~*)
BLongest prefix match
CExact match (=)
DDefault location (/)
✗ Incorrect
nginx first checks for an exact match location block marked with '='.
If multiple prefix locations match, which one does nginx choose?
ALongest prefix
BShortest prefix
CFirst defined in config
DRandom
✗ Incorrect
nginx selects the longest matching prefix location.
What does the '~*' modifier mean in an nginx location?
APrefix match
BCase-sensitive regex
CExact match
DCase-insensitive regex
✗ Incorrect
'~*' means case-insensitive regular expression match.
When does nginx use the default location '/'?
AAlways
BIf no other location matches
COnly for exact matches
DOnly for regex matches
✗ Incorrect
nginx uses the default location '/' if no other location matches the request URI.
Which location type has the lowest priority in nginx matching?
ADefault location (/)
BPrefix match
CExact match (=)
DRegular expression (~ or ~*)
✗ Incorrect
The default location '/' is used only if no other location matches.
Explain the priority order nginx uses to match a request URI to a location block.
Think about how nginx tries to find the most specific match first.
You got /4 concepts.
Describe the difference between prefix match and regular expression match in nginx location blocks.
Consider how nginx interprets the location block modifiers.
You got /4 concepts.
Practice
(1/5)
1. Which type of location block does nginx check first when matching a request URL?
easy
A. Prefix match without any modifier
B. Exact match using = modifier
C. Regular expression match using ~ or ~*
D. Prefix match with ^~ modifier
Solution
Step 1: Understand nginx location matching order
nginx first looks for an exact match location block marked with =.
Step 2: Confirm priority of exact match
If an exact match is found, nginx immediately uses it without checking other blocks.
Final Answer:
Exact match using = modifier -> Option B
Quick Check:
Exact match = first checked [OK]
Hint: Exact match with = is always checked first [OK]
Common Mistakes:
Thinking prefix matches are checked before exact matches
Confusing ^~ modifier priority
Assuming regex matches are checked first
2. Which of the following is the correct syntax for a location block that uses a case-insensitive regular expression match?
But requests to /images/photo.jpg return 'Prefix match' instead of 'Prefix ^~ match'. What is the likely cause?
medium
A. Two prefix locations with same path cause nginx to pick first declared
B. ^~ modifier is ignored if regex location exists
C. Regex location always has higher priority than ^~
D. Syntax error in ^~ location block
Solution
Step 1: Understand prefix location conflicts
Two prefix locations with identical paths cause nginx to use the first declared one.
Step 2: Check config order
The location /images/ block appears before location ^~ /images/, so nginx picks the first.
Final Answer:
Two prefix locations with same path cause nginx to pick first declared -> Option A
Quick Check:
First prefix wins if paths identical [OK]
Hint: Avoid duplicate prefix locations; nginx picks first declared [OK]
Common Mistakes:
Assuming ^~ always overrides prefix regardless of order
Thinking regex always beats ^~
Believing syntax error causes this behavior
5. You want nginx to serve static files under /static/ using a prefix match but avoid regex checks for these URLs for performance. Which configuration achieves this best?
hard
A. location /static/ { root /var/www/static; }
B. location ~* /static/ { root /var/www/static; }
C. location ^~ /static/ { root /var/www/static; }
D. location = /static/ { root /var/www/static; }
Solution
Step 1: Understand ^~ modifier effect
Using ^~ tells nginx to stop searching regex locations if this prefix matches.
Step 2: Apply to static files
Setting location ^~ /static/ ensures static files served quickly without regex overhead.
Final Answer:
location ^~ /static/ { root /var/www/static; } -> Option C
Quick Check:
^~ prefix disables regex checks [OK]
Hint: Use ^~ prefix to skip regex for performance [OK]