0
0
Nginxdevops

Wildcard and regex server names in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a wildcard server name in nginx?
A wildcard server name uses an asterisk (*) to match multiple subdomains or domain patterns. For example, *.example.com matches app.example.com, blog.example.com, etc.
Click to reveal answer
intermediate
How do you define a regex server name in nginx?
You define a regex server name by prefixing the server name with a tilde (~). For example, server_name ~^www\d+\.example\.com$; matches www1.example.com, www123.example.com, etc.
Click to reveal answer
intermediate
What is the difference between a wildcard and a regex server name in nginx?
A wildcard uses simple patterns with an asterisk (*) to match subdomains, while regex uses full regular expressions for more flexible and complex matching.
Click to reveal answer
advanced
How does nginx prioritize server names when multiple match?
Nginx prioritizes exact server names first, then wildcard names starting with an asterisk, then wildcard names ending with an asterisk, and finally regex server names.
Click to reveal answer
advanced
Write an nginx server_name directive to match any subdomain of example.com except 'www'.
Use a regex to exclude 'www': <br>server_name ~^(?!www\.)[^.]+\.example\.com$;<br>This matches any subdomain except 'www.example.com'.
Click to reveal answer
Which nginx server_name matches all subdomains of example.com?
A~^www\d+\.example\.com$
B~^example\.com$
Cexample.*
D*.example.com
How do you indicate a regex server name in nginx?
APrefix with a tilde (~)
BUse an asterisk (*)
CUse square brackets []
DUse curly braces {}
Which server_name has the highest priority in nginx?
AWildcard server names starting with *
BExact server names
CRegex server names
DWildcard server names ending with *
What does the server_name directive ~^www\d+\.example\.com$ match?
Awww followed by one or more digits, like www1.example.com
BAny subdomain of example.com
COnly www.example.com
DAll domains ending with example.com
Which of these is NOT a valid wildcard server_name in nginx?
A*.example.com
Bwww.*
C*example.com
D~^.*\.example\.com$
Explain how to use wildcard and regex server names in nginx and when to choose each.
Think about simple subdomain matching vs complex patterns.
You got /4 concepts.
    Describe nginx server_name matching priority and why it matters.
    Consider what happens if multiple server names match a request.
    You got /3 concepts.