0
0
Nginxdevops~10 mins

Wildcard and regex server names in Nginx - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a server block that listens to all subdomains of example.com.

Nginx
server {
    server_name [1];
    listen 80;
}
Drag options to blanks, or click blank then click option'
A*.example.com
Bexample.*
Cexample.com
Dwww.example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wildcard at the end like example.* does not work.
Using the exact domain name does not match subdomains.
2fill in blank
medium

Complete the code to define a server block that matches any domain ending with .test.

Nginx
server {
    server_name ~[1];
    listen 80;
}
Drag options to blanks, or click blank then click option'
A\\.test
B^test\\.
Ctest$
D\\.test$
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping the dot causes it to match any character.
Placing the caret (^) at the start matches beginning, not end.
3fill in blank
hard

Fix the error in the regex server_name to match domains starting with 'app' followed by any characters.

Nginx
server {
    server_name ~[1];
    listen 80;
}
Drag options to blanks, or click blank then click option'
Aapp.*$
B^app.*$
C^app$
Dapp^.*$
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the caret causes the regex to match 'app' anywhere, not just at start.
Placing caret in the middle is invalid.
4fill in blank
hard

Fill both blanks to create a server block matching domains starting with 'dev' or 'test' followed by '.example.com'.

Nginx
server {
    server_name ~^([1]|[2])\.example\.com$;
    listen 80;
}
Drag options to blanks, or click blank then click option'
Adev
Bprod
Ctest
Dstage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong domain prefixes like 'prod' or 'stage'.
Not escaping dots causes wrong matches.
5fill in blank
hard

Fill all three blanks to create a server block matching any subdomain of 'example.com' except 'www'.

Nginx
server {
    server_name ~^(?![1])[2]\.example\.[3]$;
    listen 80;
}
Drag options to blanks, or click blank then click option'
Awww
B[a-z0-9-]+
Ccom
Dnet
Attempts:
3 left
💡 Hint
Common Mistakes
Not using negative lookahead causes 'www' to match.
Using wrong top-level domain like 'net' instead of 'com'.