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 does the ~ operator do in nginx configuration?
The ~ operator tells nginx to perform a case-sensitive regular expression match on the requested URI.
Click to reveal answer
beginner
What is the difference between ~ and ~* in nginx?
~ is for case-sensitive regex matching, while ~* is for case-insensitive regex matching.
Click to reveal answer
intermediate
How would nginx treat the location block location ~* \.jpg$?
It matches any URI ending with '.jpg' or '.JPG' or any case variation, because ~* makes the regex case-insensitive.
Click to reveal answer
intermediate
Why use regex matching in nginx locations instead of prefix matching?
Regex matching allows flexible and precise matching patterns, like matching file extensions or specific URI patterns that prefix matching can't handle.
Click to reveal answer
advanced
What happens if multiple location blocks match a request in nginx?
Nginx first checks prefix matches, then regex matches in order. The first matching regex location is used. Regex locations have higher priority than prefix matches if they match.
Click to reveal answer
Which nginx operator performs a case-insensitive regex match?
A^~
B~*
C=
D~
✗ Incorrect
The ~* operator performs case-insensitive regex matching.
What does the ~ operator in nginx do?
APrefix match
BCase-insensitive regex match
CExact match
DCase-sensitive regex match
✗ Incorrect
The ~ operator performs a case-sensitive regex match.
Which location block matches URIs ending with '.PNG' or '.png'?
Alocation ~* \.png$
Blocation ~ \.png$
Clocation = \.png$
Dlocation ^~ \.png$
✗ Incorrect
~* makes the regex case-insensitive, matching '.PNG' and '.png'.
If both prefix and regex locations match a request, which does nginx choose?
ARegex location
BPrefix location
CThe longer prefix location
DThe first defined location
✗ Incorrect
Nginx prefers regex locations over prefix locations if a regex matches.
What symbol is used for exact match in nginx location blocks?
A~*
B~
C=
D^~
✗ Incorrect
The = symbol is used for exact URI matches.
Explain the difference between ~ and ~* operators in nginx location blocks.
Think about how uppercase and lowercase letters are treated.
You got /4 concepts.
Describe how nginx decides which location block to use when multiple blocks match a request.
Consider the matching order and priority rules.
You got /4 concepts.
Practice
(1/5)
1. What does the ~ operator mean in an nginx location block?
easy
A. It matches any request regardless of URL.
B. It performs a case-insensitive regular expression match.
C. It performs a case-sensitive regular expression match.
D. It matches the exact string only.
Solution
Step 1: Understand nginx regex operators
The ~ operator in nginx is used for regex matching that is case-sensitive.
Step 2: Differentiate from ~*
The ~* operator is for case-insensitive regex matching, so it is different from ~.
Final Answer:
It performs a case-sensitive regular expression match. -> Option C
Quick Check:
~ = case-sensitive regex match [OK]
Hint: Remember: ~ is case-sensitive, ~* is case-insensitive [OK]
Common Mistakes:
Confusing ~ with ~* for case sensitivity
Thinking ~ matches exact strings only
Assuming ~ matches all requests
2. Which of the following is the correct syntax to match URLs case-insensitively using regex in nginx?
easy
A. location ~* /images/ { }
B. location = /images/ { }
C. location ~ /images/ { }
D. location /images/ { }
Solution
Step 1: Identify case-insensitive regex syntax
In nginx, ~* is used for case-insensitive regex matching.
Step 2: Check other options
~ is case-sensitive, = is exact match, and no operator means prefix match.
Final Answer:
location ~* /images/ { } -> Option A
Quick Check:
Case-insensitive regex = ~* [OK]
Hint: Use ~* for case-insensitive regex in nginx location [OK]
Common Mistakes:
Using ~ instead of ~* for case-insensitive matching
The regex /images/(.*\.png$ has an opening parenthesis but no closing parenthesis.
Step 2: Validate other parts
The ~* operator is valid for case-insensitive match, proxy_pass URL looks valid, and curly braces are present.
Final Answer:
Missing closing parenthesis in regex -> Option A
Quick Check:
Regex parentheses must be balanced [OK]
Hint: Count parentheses in regex to avoid syntax errors [OK]
Common Mistakes:
Forgetting to close parentheses in regex
Confusing ~ and ~* usage
Ignoring syntax errors in regex patterns
5. You want to serve all URLs ending with .css or .CSS using a regex match in nginx. Which location block correctly matches both cases efficiently?
hard
A. location ~ \.css$ { }
B. location ~* \.css$ { }
C. location ~ \.css$|\.CSS$ { }
D. location ~* \.css$|\.CSS$ { }
Solution
Step 1: Understand case-insensitive matching
Using ~* makes the regex case-insensitive, so it matches both '.css' and '.CSS'.
Step 2: Evaluate other options
location ~ \.css$ { } uses case-sensitive ~, so it misses '.CSS'. Options C and D have incorrect regex syntax with unescaped pipes and redundant patterns.
Final Answer:
location ~* \.css$ { } -> Option B
Quick Check:
Use ~* for simple case-insensitive regex [OK]
Hint: Use ~* with simple regex to match case-insensitive extensions [OK]
Common Mistakes:
Using ~ and missing uppercase matches
Trying to match cases with complex regex instead of ~*