0
0
Nginxdevops~5 mins

Regex match (~, ~*) in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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~
What does the ~ operator in nginx do?
APrefix match
BCase-insensitive regex match
CExact match
DCase-sensitive regex match
Which location block matches URIs ending with '.PNG' or '.png'?
Alocation ~* \.png$
Blocation ~ \.png$
Clocation = \.png$
Dlocation ^~ \.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
What symbol is used for exact match in nginx location blocks?
A~*
B~
C=
D^~
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.